You need to sign in to do that
Don't have an account?
Phil Witzmann
Modify Picklist after a value is picked
Hi,
I have a picklist with 6 values (1, 2, 3, 4, 5, 6)
The default value is 1.
When someone chooses another value from that picklist (imagine 2), I would like that value 1 and 2 were not able to be picked again.
How can I do this?
Thanks
I have a picklist with 6 values (1, 2, 3, 4, 5, 6)
The default value is 1.
When someone chooses another value from that picklist (imagine 2), I would like that value 1 and 2 were not able to be picked again.
How can I do this?
Thanks
Could you ellaborate more on your design?
Do you want the values to disappear for any record? E.g. If record A uses "1", then record B, record C, record D will not have 1 listed as an option?
To modify the picklist values you're looking at utilizing the metadata api, which is tricky (but doable).
I would suggest a different approach here. Instead of utilizing an actual picklist field type, why not a separate sobject or custom setting? That way you could populate the "picklist" via data loader or Apex. This has the added benefit of deleting (or adding) picklist values through simple Apex triggers or Flows, where as with a Picklist field type you would need to bring a more complex Metadata API callout into the picture.
Now, when you implement a trigger you need to compare the current value with the values in this list (either a csv field or a related list) and throw an error if it's repeating.
In the Before context of the trigger, perform a SOQL on the same object with the "Where" clause as selected picklist value. If the list size is greater than 1, through error using addError.
It means, one picklist value can only be used only once. It cannot be used second time.
Try with below code it will help !!
Few things you need to modify to justify your requirment .
Change Opportunity to your object name .
Change StageName to your pickList field name .
Chnage the variable name accordigly .
Let me know if it helps !!
Thanks
Manoj