If I select a value on a lookup field on a particular record, is there a way that this selected lookup value gets hidden and does not display in another record? Lets say I have an object Object1__c which has a lookup field (Object2__c). Object2__c has 3 records "A, B and C". Now I create a new record on Object1__c and select value "A" on lookup field. Now when I create a 2nd record on Object1__c , the lookup field should only give me the option to select either B or C. not A. Is this poosible?
[SalesForce] Remove lookup value once selected in a record
Related Solutions
As sfdcfox stated, not a good idea to use the SF libraries.
Here is a link to a blog post by Jeff D. that works well for roll your own Salesforce lookup popup window:
It’s a handy little button that pops up whenever you need to search for related records. It does a pretty good job but it has some serious drawbacks:
- It’s virtually impossible to modify your search criteria. What if you want your users to do some crazy search based upon custom logic or search a field that is not typically available? Sorry… you are out of luck. Not possible.
- It’s terrible for creating new records. Let’s say that a user searches for a specific related record and it (absolutely) doesn’t exist. To create the new record they need to close the lookup window, navigate to the tab to create the new related record, create the new record, then go back to the original record they were either editing or creating, pop up the lookup window again and find their newly created record. Wow! That’s a lot of work.
- “Quick Create” is evil! You can enable the “Quick Create” option for an entire org but don’t do it! It displays, by default, on the tab home pages for leads, accounts, contacts, forecasts, and opportunities! The major problems are that you can only create new records for these 5 objects (what about the other ones!?), you can’t customize the fields on the page and validation rules don’t fire (can you say, “bad data”).
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
The only place an OR can be applied currently is either in a Formula or a Decision. That being said, you can use a formula to separate the values based on the delimiter, and run each result separately. This blog post has some excellent information on parsing multi-picklists and working with the data there.
Best Answer
Lookup fields such as your
Object1__c.Object2__c
field can have a lookup filter defined. To exclude the already selectedObject2__c
instances in such a filter, you then need say a checkbox fieldObject2__c.InUse__c
to use in the filter expression. A trigger can populate that checkbox field on insert/update/delete/undelete ofObject1__c
.The trigger would look like this in its basic form:
and the filter criteria on the
Object1__c.Object2__c
field would be: