[SalesForce] Query on CreatedDate and LastModifiedDate

select id from Opportunity where CreatedDate < LastModifiedDate LIMIT 1;

Why there is parsing error when we compare CreatedDate and LastModifiedDate?

Best Answer

Salesforce does not allow direct field to field comparison in SOQL query. Workaround for this is mentioned here

In your case, add new formula checkbox field called CreatedLessThenModified__c on Opportunity:

CreatedDate < LastModifiedDate

then the following soql will work:

select id
from Opportunity
where CreatedLessThenModified__c = true
limit 1;