[SELECT Id,Name FROM Account WHERE Id IN :Trigger.New AND Id NOT IN (SELECT AccountId FROM Opportunity)]
  • It only returns all the accounts which were updated/inserted or deleted in the trigger without those who are linked to any opportunity in the database. – Martin Lezer Apr 19 '18 at 9:14
  • @MartinLezer Please do not answer questions in comments. – sfdcfox Apr 19 '18 at 9:16
  • 3
    @Vishal Sharma, what part of the query dont you understand? have you read the SOQL and SOSL Reference Guide ? – glls Apr 19 '18 at 13:57
  • I think you'd find the query would likely be easier to understand if read in context of the code that surrounds it. It's obviously from a trigger. It's not a "stand alone" query that you'd execute via anonymous apex. – crmprogdev Apr 19 '18 at 15:21
  • @glls i am in between AND Id NOT IN was not clear – Vishal Sharma Apr 20 '18 at 12:35

This query finds all accounts in the current trigger execution context (Id IN :Trigger.new) that do not have an opportunity (Id NOT IN (SELECT AccountId FROM Opportunity)).

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.