Latest Updates

Travel to Technology

Dayton Metro Library

How to skip salesforce lookup filter?

How to Avoid Performing a Salesforce Lookup Filter Uses a Picklist?

There are many scenario user don’t want to fire lookup filter like while running some apex job or generating billing related record.

How to skip lookup filter?

1. Create a checkbox field on the User object.

Screen Shot 2017-03-13 at 9.17.01 PM

2. Go to lookup filter and add below condition along with existing condition

Screen Shot 2017-03-13 at 9.18.03 PM

3. While starting a batch job update current user with Skip lookup Filter flag to “TRUE”

list<User> lstUser = [Select ID, Skip_Lookup_Filter__c from User where ID =:UserInfo.getUserId()];
for(User iterator: lstUser) {
   iterator.Skip_Lookup_Filter__c = True;
}
Update lstUser;

4. On finish method update the user Skip Lookup Filter flag to “False”

list<User> lstUser = [Select ID, Skip_Lookup_Filter__c from User where ID =:UserInfo.getUserId()];
for(User iterator: lstUser) {
   iterator.Skip_Lookup_Filter__c = false;
}
Update lstUser;

Note: Keep in mind – While batch job is running at the same time user trying to create some record manually the lookup filter will not fire since skipped filter for that user.