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
David Autry 4David Autry 4 

SOQL - Multipicklist INCLUDES Multipicklist

Been banging my head against the wall for a bit on this one.  Given a global picklist that is added to two objects can a SOQL query be constructed such that the query will return a collection of objects A or B where the global picklist on each contains one matching value in the set pair?

Given MultipickList__c is a global picklist on ObjectA and ObjectB :

SELECT Id FROM ObjectA WHERE Multipicklist__c INCLUDES(ObjectB.Multipicklist__c)

Thank you.

David

Best Answer chosen by David Autry 4
David Autry 4David Autry 4

Settled on a FOR loop.  Broke ObjectA.Multipicklist__c into an array and used it to query against ObjectB.

 

                string[] multipickA = ObjectA.MultiPickList__c.split(';');
                List<ObjectB> finalList = new List<ObjectB>();
                integer i = 0;
                for (string s : multipickA)
                {
                    List<ObjectB> tempList = [SELECT Id 
                                                          FROM ObjectB
                                                          WHERE MultiPickList__c INCLUDES(:multipickA[i])]
                    finalList.addall(tempList);
                    i++;                    
                }

 

If there is a more elegant solution please let me know.

Thanks all.

All Answers

David Autry 4David Autry 4
I've tried ..
  1. WHERE MultiPicklist__c INCLUDES (ObjB.Multipicklist__c)
  2. Converting ObjB.Multipicklist__c to a list (comma delimited)
  3. ObjB.Multipicklist__c to a set (semi-colon delimited)
  4. Converting ObjB.Multipicklist__c to a string with % 
  5. I tried the delimited strings/lists/sets based on ... https://help.salesforce.com/articleView?id=000334304&type=1&mode=1

Here are the actual values from DEBUG:

PickList A = 09ab2636-6edb-480f-8acc-7f090b7e6be2;26fd683b-201a-4f1a-abc8-d8a1c8d26cc3

Picklist B = 09ab2636-6edb-480f-8acc-7f090b7e6be2; 334ab04f-e75e-4a04-9a12-fbc835b344e8


Given that both picklists contain '09ab2636-6edb-480f-8acc-7f090b7e6be2' I'd like SOQL to return that object ...


I'm thinking this is a string syntax thing?  Probably something simple I'm missing.


Thanks all.
David Autry 4David Autry 4

Settled on a FOR loop.  Broke ObjectA.Multipicklist__c into an array and used it to query against ObjectB.

 

                string[] multipickA = ObjectA.MultiPickList__c.split(';');
                List<ObjectB> finalList = new List<ObjectB>();
                integer i = 0;
                for (string s : multipickA)
                {
                    List<ObjectB> tempList = [SELECT Id 
                                                          FROM ObjectB
                                                          WHERE MultiPickList__c INCLUDES(:multipickA[i])]
                    finalList.addall(tempList);
                    i++;                    
                }

 

If there is a more elegant solution please let me know.

Thanks all.

This was selected as the best answer