1

I like to query Custom-metadata multiple values with like operator. I am able to successfully query with a single like i.e. [... From City_Setting__mdt where Label Like 'EmailToSign%' ...] //returns few records.

But I like to add more filter on Label column i.e. [... From City_Setting__mdt where Label Like 'EmailToSign%' OR Label Like 'SendCopy%'...] and generates an error.

Failed attempt-1:

Set<String> voiceMailOptions = new Set<String>{'EmailToSign%', 'SendCopy%'};
[... From City_Setting__mdt where Label Like : voiceMailOptions order by Label ASC]; //returns no row though there are values

Failed attempt-2:

[..From City_Setting__mdt where Label Like 'EmailToSign%' OR Label Like 'SendCopy%' order by Label ASC]; //returns no row though there are values

Any help would be appreciated. Thanks, Mahesh.

1
  • We can use the following operators with SOQL over custom metadata types. IN and NOT IN =, >, >=, <, <=, and != LIKE, including wild cards AND – dgk Feb 11 '20 at 6:47
0

Your first attempt will not work with Custom Metadata and Objects as well, because like accepts only one argument at a time. In the case of Objects, you can use an OR operator.

The second attempt works with Objects and unfortunately does not work with Custom Metadata.

But as it's a custom metadata object you can write two queries to get the data and combine the result, as querries against Metadata objects are not counted in SOQL Governor Limits.

Please note that the limit on the number of rows in the query still applies here.

// Query 1
List<City_Setting__mdt> firstRes = [... From City_Setting__mdt where Label Like 'EmailToSign%' ...];
// Query 2
List<City_Setting__mdt> secRes = [... From City_Setting__mdt where Label Like 'SendCopy%' ...];
// Combine the result in a list.
List<City_Setting__mdt> combineRes = firstRes.addAll(secRes);

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.