AnswerBun.com

How to query only accounts that don't have attachments

Salesforce Asked by Akouayri Hamza on January 2, 2022

Use Case: get all accounts that don’t have a related attachment
I have used this query but I get an error when I add the Bold part

SELECT Id, (SELECT Id, StageName FROM Opportunities WHERE StageName = 'Closed Won'),(SELECT Title,ParentId FROM CombinedAttachments) FROM Account Where Id IN (SELECT AccountId FROM Opportunity WHERE StageName = 'Closed Won') AND ID NOT IN (SELECT ParentId FROM CombinedAttachments)

The bold part below throws the error shown in the image below

AND ID NOT IN (SELECT ParentId FROM CombinedAttachments)

ERROR

One Answer

CombinedAttachments (note the plural) is the name of a relationship. CombinedAttachment is the name of the sObject.

You'd use the relationship name when performing a subquery. When you perform a semi-join in your WHERE clause, as in your bolded text here, you must use the actual sObject API name.

You've also got IN NOT instead of NOT IN, as was pointed out in the comments.

Answered by David Reed on January 2, 2022

Add your own answers!

Related Questions

Unable to use array.includes() with SSJS?

2  Asked on December 12, 2021 by balwill

     

AMPScript IF statement or Loop?

2  Asked on December 12, 2021 by bryce-mi

   

Remove Verification Code for one User

0  Asked on December 10, 2021 by teemo_smr

   

What is wrong with this LIKE in an Query?

0  Asked on December 10, 2021 by johann-mayer

 

SOQL Aggregate functions circumventing limits?

0  Asked on December 10, 2021 by jonathanwiesel

     

trigger to validate price ranges

1  Asked on December 10, 2021 by lus-aguiar

   

Can’t see global header in community

1  Asked on December 7, 2021 by nicstella

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir