TransWikia.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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP