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

WHERE IN(myArray) query



I need to run the following query in an apex trigger:


I need to select contact where Account.Name IN(myArrOfAccount)


How dow I run this in apex?


Here is a sample code that I am trying to run:



String[] accs = myObj.MyMultiSelectPickList__c.split(';');

				Contact[] contacts = [select c.Email from Contact c where c.Account.Name IN :accs and c.ActiveCustomUser__c = true];



The above code simply took all the values from the pick list intead of only the selected values.


Any ideas.


Thanks in advance.


Hi kminev,


in SOQL the join IN function work on an object  , not with a string list. (See this link )


For your example:


..WHERE c.ActiveCustomUser__c = true and c.AccountName IN (SELECT Name from Account) ] ;


In my opinion, you can use list<string> instead of string array.


Give the array declaration like  List<string> accs = new List<String>();


Hope this helps.