Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

How to skip salesforce lookup filter?

 . Apex  . How to skip salesforce lookup filter?

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.

Comments

Post a Comment