[SalesForce] Getting ‘Bind variables only allowed in Apex code’ when attempting this query

SELECT Id, Last_stage_changed_date__c, CreatedDate 
FROM Opportunity 
WHERE Last_stage_changed_date__c < CreatedDate

Last_stage_changed_date__c is of the Date type. I feel like I'm doing something dumb but I can't spot it.

Getting the error:

Bind variables only allowed in Apex code

Best Answer

You cannot compare one field to another in SOQL, regardless of context. If you want to compare a custom date field to CreatedDate, you will need a separate checkbox formula field to do the comparison for you, then you can filter on this field being true.

Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.