I am attempting to query a custom object that has a master detail lookup relation with opportunities. When I build the query dynamically I am getting an SOQL error:
System.QueryException: unexpected token: 'A000000VmhPyIAJ'
The first three characters of the ID have been dropped in that exception, the full ID is:
006A000000VmhPyIAJ
If I dump the query string with System.debug I get this (with the full ID):
SELECT id, isdeleted, name, createddate, createdbyid, lastmodifieddate, lastmodifiedbyid, systemmodstamp, lastactivitydate, opportunity__c, issue__c, description__c, ... FROM Exceptions__c WHERE Opportunity__c = 006A000000VmhPyIAJ
If I pass this exact same string into the database.query() I get results as expected.
Anyone have any idea what is causing this? The code that is generating that query is a library that I use for hundreds of other queries through out our custom Apex, and none of those queries are failing.
The actual query block:
try {
String query = 'SELECT id, isdeleted, name, createddate, createdbyid, lastmodifieddate, lastmodifiedbyid, systemmodstamp, lastactivitydate, opportunity__c, issue__c, description__c, ... FROM Exceptions__c WHERE Opportunity__c = 006A000000VmhPyIAJ';
exceptions = database.query( query );
} catch(DmlException e) {
System.debug('DmlException: ' + e);
}