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
Nathan Prats 17Nathan Prats 17 

SOQL Query on Opportunity !=


I'd like to execute something like this : 

FROM Opportunity
WHERE OwnerId != Opportunity.Account.OwnerId

Unfortunately, I got this error message. 
FROM Opportunity
ERROR at Row:3:Column:17
Bind variables only allowed in Apex code

Is there a work around ?
NagendraNagendra (Salesforce Developers) 
Hi Nathan,

May I suggest you please check with below which might help you
Select Id From Opportunity Where OwnerId not in (select OwnerId from Account)
Also seems nothing wrong with the above code is well.

Please let us know if this helps.

Best Regards,
HI Nathan Prats 17,

To achieve  above requirement  you  have to create a formula field in account    using bellow formula

IF( OwnerId = Account.OwnerId , 'true', 'false')​  

return type should be text

and then write a query like bellow 

​SELECT Id,name ,, FROM Opportunity where accountowner__c='true'

accountowner__c is forumla field i have created in developer organisation  if you have any doubt please let me know

Thank you
Hi Nathan Prats 17,

for clarification i am asking these question

you want to retrieve the opportunity records  when the owner of oppotunity and acccount is same .am i right?

Thank you

Nathan Prats 17Nathan Prats 17

When they are different. 
HI Nathan Prats 17,

sorry i have given code for  owners are same .

Thank you