I have a SOQL query in my Apex code similar to this:
List<My_Packaged_Object__c> myMethod(Set<Id> targetIds) {
return [
SELECT id, name, lookup_field_a__c, lookup_field_b__c,
lookup_field_a__r.name, lookup_field_b__r.name
FROM My_Packaged_Object__c
WHERE lookup_field_a__c IN :targetIds
OR lookup_field_b__c IN :targetIds
ORDER BY name
];
}
This method is within a class in a managed package.
Let's say that targetIds set contains only 1 ID, there are 100 records of My_Packaged_Object__c type, and only 10 of those fulfill the query condition; when the method is called, it returns all 100 records. It's as if the where-clause is ignored.
While investigating logs on the affected sandbox org, I saw that this query was transformed into a query similar to this:
SELECT id, name, prefix__lookup_field_a__c, prefix__lookup_field_b__c,
lookup_field_a__r.name, prefix__lookup_field_b__r.name
FROM My_Packaged_Object__c
WHERE lookup_field_a__c = :tmpVar1
OR lookup_field_b__c = :tmpVar2
ORDER BY name
(formatted for easier reading)
Note that some fields have package prefix added, and some don't. Also note that IN keyword was changed into equality sign.
Does anyone know what could be the reason for this behaviour? There are some custom, user-added fields on My_Packaged_Object__c, but they all have their own prefix, none of them have the same API nameas the packaged fields, and they're not referenced in the query.
Database.query()
method to retrieve data.IN
and=
are interchangeable.)