+ Start a Discussion
Domnic JohnsonDomnic Johnson 

UserId to be excluded from trigger

If((LeadList[0].OwnerId != '005User1') || (LeadList[0].OwnerId != '005User2) || (LeadList[0].OwnerId != '005User3'))

Need help writing this line better
Raj VakatiRaj Vakati
You can use set or list or map to do this 
try this code
Set<Id> userIds = new Set<Id>{'005User1', '005User2','005User3'} ;

Niraj Kr SinghNiraj Kr Singh
Hi Domnic Johnson,

Direct comparing with id is not a good paractice. While you deploy in different org/production, you will not found those Id and you trigger will not work.
You can do in following way:
1: @Raj V mentioned here.

2: Do soql on USER object and put WHERE condition accordingly to get relavent users only. Like:
   Map<Id,User> mapUsers = new Map<Id, User>([Select Id, Name, ProfileId, Profile.Name From User Where Name Like '%Test%']); //Any other filter
   If(mapUsers.containsKey(LeadList[0].OwnerId)) {
         //Your Logic

3: Create custom setting / Label, Keep all Ids there and fetch into trigger code in a Set variable Like that:
    //Taking custome label:  UserIds .
   // Keep id with comma seperated. u001,u002....
    //YOu can deploy and update according to differnt orgs.
     String uIds = Label.UserIds;
     Set<String> userIdsSet = new Set<String>();
    if(!String.isBlank(uIds)) {
           List<String> userIds = uIds.split(',');

         //YOur logic

Might be it will help you !!

Domnic JohnsonDomnic Johnson
Thank you both for responding back.

I tried what Raj suggested and am getting this error
Salesforce could not create this lead because of the reason listed below. For more information about this error or help with Web-to-Lead, please contact Customer Support.

Reason: common.apex.runtime.TriggerExecutionException: Apex trigger LimitLeads caused an unexpected exception, contact your administrator: LimitLeads: execution of BeforeUpdate

caused by: System.ListException: List index out of bounds: 0: ()
    Lead Capture Page: Not available.