Apex · Salesforce

How to skip salesforce lookup filter?

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.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s