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
Khalid AbdullahKhalid Abdullah 

SOQL: How do you return records if OwnerId of the main object and the OwnerId of the Lookup Object do not Match?

Hello all!

Novice question here: Trying to write a SOQL query which will compare the OwnerId of the Contact to the OwnerId of the Lookup Relationship Object and return only records where OwnerIds on both objects don't match.

The two objects are: 
1. Contacts (Main Object)
2. Lookup Relationship: Sub Zones (Zone__c) 

The Contacts object contains a field with a lookup relationship to the Sub Zones Object (Zone__c)

Both the Contact and the Sub Zone have an owner. We assign Sub Zones if the owners are both are identical.

How would I write a SOQL Query to find the records where they do not match?
Best Answer chosen by Khalid Abdullah
SaiGSaiG
Try the solution mentioned in this link: https://help.salesforce.com/HTViewSolution?id=000187460&language=en_US

- Sai

All Answers

SaiGSaiG
Try the solution mentioned in this link: https://help.salesforce.com/HTViewSolution?id=000187460&language=en_US

- Sai
This was selected as the best answer
Khalid AbdullahKhalid Abdullah
Hello Sai,

Thanks so much for your post, we were spinning our wheels on this for quite some time but it's good to know we should just create a custom field for it and proceed that way (at least until an enhancement is introduced to the SOQL environment for this).

Best regards,

Khalid Abdullah