5

Custom Metadata supports a limited SOQL syntax, and OR statements are not supported. From the documentation:

What is an alternative to the below SOQL if Salesforce does not support OR in this case?

SELECT Call_Center_Display_Script__c
FROM VDN_Mapping__mdt 
WHERE obj_name__c =: objNamePassed 
OR (obj_name__c = '' and isactive = true )
6

As you can perform an unlimited number of queries against __mdt (relevant documentation), I'd suggest simply breaking this up into two queries.

Map<Id, VDN_Mapping__mdt> first_query = new Map<Id, VDN_Mapping__mdt>([SELECT Call_Center_Display_Script__c
FROM VDN_Mapping__mdt 
WHERE obj_name__c =: objNamePassed]);

Map<Id, VDN_Mapping__mdt> second_query = new Map<Id, VDN_Mapping__mdt>([SELECT Call_Center_Display_Script__c
FROM VDN_Mapping__mdt 
WHERE obj_name__c = '' and isactive = true]);

Combining the results (to achieve the same effect as using a single query with OR) is as simple as adding all the results from one map to the other

first_query.putAll(second_query);

Using a map ensures that you don't end up with duplicate results (a Set could also be used).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.