function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Victor BogolyubovVictor Bogolyubov 

Very strange (at least for me) SOQL parsing error

Hello,
I got Unknown error parsing query error. Can somebody explain what is going on, please? Thank you.

1. This is OK
SELECT Contact__r.Id, Contact__r.OwnerId, Account__r.Id, Account__r.OwnerId, Student__r.OwnerId
FROM Student_Relationship__c
WHERE Student__r.OwnerId  !='0056C000003GwJnQAK'
  AND Account__r.OwnerId != '0056C000003GwJnQAK'
LIMIT 20

2. This is OK too
SELECT Contact__r.Id, Contact__r.OwnerId, Account__r.Id, Account__r.OwnerId, Student__r.OwnerId
FROM Student_Relationship__c
WHERE Student__r.OwnerId  !='0056C000003GwJnQAK'
  AND Contact__r.OwnerId != '0056C000003GwJnQAK'
LIMIT 20

3. But THIS one is Unknown error parsing query
SELECT Contact__r.Id, Contact__r.OwnerId, Account__r.Id, Account__r.OwnerId, Student__r.OwnerId
FROM Student_Relationship__c
WHERE Student__r.OwnerId  !='0056C000003GwJnQAK'
  AND Contact__r.OwnerId != Account__r.OwnerId
LIMIT 20
 
Best Answer chosen by Victor Bogolyubov
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Victor,

This is expected behaviour from salesforce. We cannot compare two fields in SOQL query. Please find the below article for the same.

https://help.salesforce.com/s/articleView?id=000331053&type=1 (https://help.salesforce.com/s/articleView?id=000331053&type=1)

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Victor,

This is expected behaviour from salesforce. We cannot compare two fields in SOQL query. Please find the below article for the same.

https://help.salesforce.com/s/articleView?id=000331053&type=1 (https://help.salesforce.com/s/articleView?id=000331053&type=1)

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Victor BogolyubovVictor Bogolyubov
Thank you!