+ Start a Discussion
EnryEnry 

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.

Br

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
}