[SalesForce] Querying against a multi-select picklist

I'm trying to run a SOQL query that pulls campaigns where the value of a custom picklist field (Newsletter_Subscriptions__c) is included in a Contacts multi-select picklist fields (Newsletter_Subscriptions__c). Currently, I've dumped the Contact's picklist values into a list (contactSubscriptions) that I'm querying against but the query isn't pulling any campaigns. Any advice?

list subscriptionCampaigns = [SELECT ID FROM Campaign WHERE Newsetter_Subscriptions__c IN :contactSubscriptions];

Best Answer

If you are querying against a mulit-select picklist, you need to use includes in your query.

list subscriptionCampaigns = [
    SELECT ID FROM Campaign 
    WHERE Newsetter_Subscriptions__c INCLUDES :contactSubscriptions];

If Newsletter_Subscriptions__c is the multi-select and contactSubscriptions contains all of the values you want this should return any Campaign that has at least one selected. If you need to only select those that match all then you need to join the contactSubscriptions into a single semi-colon delimited string and have that as the only item on the list

There are some more examples in the Querying Multi-Select Picklist docs