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
CompteDeOufCompteDeOuf 

How to find the accounts & contacts with different owners

The following query works fine in SOQL

 

select account.name,name,account.ownerid,ownerid from contact limit 10

 

so all the fields are available.

 

This one is unparsable by SOQL

select account.name,name,account.ownerid,ownerid from contact where account.ownerid!=ownerid  limit 10

 

Anyway to do this ? 

Best Answer chosen by Admin (Salesforce Developers) 
qraishqraish

Are we looking to (extract) data from contact where the owner of contact is different from that of parent account's owner?

 

If that is the case, I think this query might work. Let me know your thoughts.

 

SELECT Account.OwnerId, Account.Name, Name, OwnerId

FROM Contact

WHERE OwnerId NOT IN

(SELECT OwnerID FROM Account) 

 

Raish

All Answers

qraishqraish

Are we looking to (extract) data from contact where the owner of contact is different from that of parent account's owner?

 

If that is the case, I think this query might work. Let me know your thoughts.

 

SELECT Account.OwnerId, Account.Name, Name, OwnerId

FROM Contact

WHERE OwnerId NOT IN

(SELECT OwnerID FROM Account) 

 

Raish

This was selected as the best answer
CompteDeOufCompteDeOuf

Perfect,

thanks Raish.

qraishqraish
:)
If you have few seconds, please mark it as solution for future references for someone stucked in similar situation.