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 !=

Hi, 

I'd like to execute something like this : 

SELECT Id
FROM Opportunity
WHERE OwnerId != Opportunity.Account.OwnerId

Unfortunately, I got this error message. 
MALFORMED_QUERY: 
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,
Nagendra.
 
Ramssf70Ramssf70
HI Nathan Prats 17,

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

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

return type should be text

and then write a query like bellow 

 
​SELECT Id,name ,owner.id,account.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
Ramssf70Ramssf70
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
Ramssf70, 

When they are different. 
Ramssf70Ramssf70
HI Nathan Prats 17,

sorry i have given code for  owners are same .

Thank you