I have code that works on a scratch org but isn't working in production. I've tracked it down to a query that's searching a table. The Apex code looks like this:
SELECT Id
FROM Tag__c
WHERE Name IN :LoanController.fieldTagMap.values()
ORDER BY Name
Here's LoanController.fieldTagMap
:
private static Map<String, String> fieldTagMap = new Map<String, String>{
'AppraisalExpiration__c' => 'Aprsl Expire Soon',
'RateExpiration__c' => 'Lock Expire Soon'
};
I log into production and go to the dev console and execute this query:
SELECT Id, Name
FROM Tag__c
WHERE Name IN ('Aprsl Expire Soon', 'Lock Expire Soon')
ORDER BY Name
Only the record with the name "Lock Expire Soon"
is returned. So I try this query:
SELECT Id, Name
FROM Tag__c
I get all the records including "Aprsl Expire Soon"
. I copy the version in my query and paste it into the field and save the record, no change.
Two more clues:
- If I exclude the
ORDER BY
, I get both records back, but in the wrong order. - If I retain the
ORDER BY
clause but reverse the order of fields of theIN
clause, (('Lock Expire Soon', 'Aprsl Expire Soon')
), I get both records back.
So by altering the query slightly, I can get both records back, but why should this matter? How can the order of my list of fields affect the returned records?