1

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

1
  • 1
    It seems like your query that originated the screenshot is not quite the same as the one in your post. In your screenshot, it says ID IN NOT instead of NOT IN. I'm not sure if this is what caused the error though. Commented Jul 24, 2020 at 17:36

1 Answer 1

2

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.

3
  • Thanks for that @David, I was unaware that this ever existed. Commented Jul 24, 2020 at 19:34
  • after fixing the query i got this error : INVALID_TYPE_FOR_OPERATION: entity type CombinedAttachment does not support query. Commented Jul 26, 2020 at 17:38
  • Then you'll need to build other queries using the underlying objects, Attachment and ContentDocumentLink.
    – David Reed
    Commented Jul 26, 2020 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .