0

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);

}

1 Answer 1

0

Forgot to escape single quotes on the where clause value.

WHERE Opportunity__c = '006A000000VmhPyIAJ'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.