Custom MetaData Type SOQL not giving proper results
Last updated 2022-02-10 ·Reference W-5657811 ·Reported By 47 users
Summary
When using the result of filtering(where) in for() statement with Custom Metadata Type
Filtered result is not appropriate result . It processes records that are not targets
Repro
1. Create Custom Metadata Type(Setup-> Develop-> Custom Metadata Types-> [New Custom Metadata Type])
Label: testcm
Plural Label: testcms
ObjectName: testcm
2. Create Custom Field in this CustomMetadataType(testcm__mdt)
Type: text
Field Label:testfild1
3. Click [Manage Records] and create 205 records in this CustomMetadataType(testcm__mdt)
Set the initial value of custom field to "1"
4. Set the value of the custom field of three records to "0"(e.g. test1, test2, test3 are set to 0)
5. Launch Workbench and [Apex Execute] (utilities-> Apex Execute)
6. Run the following code
for (testcm__mdt temp: [SELECT Id,MasterLabel,testfld1__c FROM testcm__mdt where testfld1__c='1']) {
if(temp.testfld1__c == '0'){
system.debug('***');
}
}
7. You can see debug log as test1, test2, test3 record IDs, this issues occurs when the record is 200 or more
Workaround
You can avoid the issues by changing it as follows
----> FROM
for (testcm__mdt temp: [SELECT Id,MasterLabel,testfld1__c FROM testcm__mdt where testfld1__c='1']) {
if(temp.testfld1__c == '0'){
system.debug(temp.Id);
}
}
----> TO
testcm__mdt[] foo = [SELECT Id,MasterLabel,testfld1__c FROM testcm__mdt where testfld1__c='1'];
for (testcm__mdt temp: foo) {
if(temp.testfld1__c == '0'){
system.debug(temp.Id);
}
}
08/10/2020 : Please note that the fix was targeted only for set of orgs in 226 so few orgs might still have the same behavior mentioned above, however, the fix will be rolled out to all the orgs in 228.
08/14/2020 : If you want to be included in the allow list so that the query behavior will be fixed in your 226 org, please reach out to Salesforce Customer Support.
Reported By (47)













Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.