function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Structure and fuction for picklist's values

I'm tring to optimize the code below.

I'm looking for a structure where i can put the picklist's values and after (with just a condition) i want check the condition for all the values in the structure.

if ((lead.Status.trim()=='Archived' || lead.Status.trim()=='False'||lead.Status.trim()=='Lead - Never'))


should be like this:

structure=['Archived','False','Lead - Never']; 
if ((lead.Status.trim()==structure))


I can not find anything, do you know how i can do this?

Thanks in advantage for any advice.


Best Answer chosen by Admin (Salesforce Developers) 
Sonali BhardwajSonali Bhardwaj

You can store your values in a Set, and check if your set contains required value.


Set<String> vals = new Set<String>{'Archived','False','Lead - Never'};
if (vals.contains(lead.Status.trim()) {
// your code