You need to sign in to do that
Don't have an account?
David 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
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
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.
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.