SOQL query on Custom Metadata Type records ignores where clause with Database.getQueryLocator
Apex , Custom Objects , Metadata
Last updated 2022-02-10 ·Reference W-7852686 ·Reported By 0 users
Summary
SOQL query used with Database.getQueryLocator on Custom Metadata Type records returns results without considering the where clause.
Repro
1) Create a custom metadata type with name "Test Metadata".
2) Create a checkbox field with name "Checkbox" to the custom metadata type.
3) Create a record for custom metadata type with checkbox field value as "false".
4) Create another record with checkbox field value as "true".
5) Open developer console and execute the below code.
String query = 'SELECT Id,label FROM Test_Metadata__mdt WHERE Checkbox__c = false';
Database.QueryLocator ql = Database.getQueryLocator(query);
Database.QueryLocatorIterator it = ql.iterator();
system.debug('testing it =' +it);
// Iterate over the records
while (it.hasNext())
{
Test_Metadata__mdt orc = (Test_Metadata__mdt)it.next();
System.debug('QueryLocator result =' +orc);
}
List<Test_Metadata__mdt> orcList = [SELECT Id,label FROM Test_Metadata__mdt WHERE Checkbox__c = false];
for(Test_Metadata__mdt orc: orcList){
System.debug(':::List result = ' + orc);
}
QueryLocator returns results with Checkbox value as true though the filter is for false.
Workaround
Use SOQL query with For or List instead of Database.QueryLocator.
Reported By (0)
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.