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
IC-TannerIC-Tanner 

'Contains' logic expression operator?

Does anyone know if there is a 'contains' logic apex operator? I have a multipicklist that I want to utilize 'contains' logic on. For example (psuedocode):
 
contact c = new contact();
if (c.multiPickList contains 'textvalue') {}
 
//'textvalue' in this case would be a multipicklist option
 
the standard equals operator == doesn't really work here as the multipicklist field functions like a text string and places all the values selected together as one string. Therefore I have no way of checking if a value is contained by the mulitpicklist unless it is the only option selected.
 
Thanks ahead of time if anyone knows a workaround for this.
 
 
Vijay RautVijay Raut
Hi Rather than checking contains in the MultiSelect Picklist value, can you just assign that Multiselect picklist value to some String and then use String contains function.

Like...

contact c = new contact();
.....
.....
String str = c.multiPickList__c;
if (str.contains('TEXTVALUE') {}
.......


Hope this will help.

Thanks,
V.R.



IC-TannerIC-Tanner
Awesome  Vijay, I wasn't aware that there was a 'contains' method. Your help was much appreciated.