1

Is there a way to get an attachment from a related object?

Example:

SELECT
    RelatedObject__r.Id
  , RelatedObject__r.OtherField
  , (SELECT RelatedObject__r.Id FROM Attachments)
  , ObjFieldOne__c
  , ObjFieldTwo__c
FROM
    CustomObj__c

Is this possible? Can't seem to find anything regarding this.

0

No. In SOQL, you can't go "up then down". The alternative would be to use two subqueries:

SELECT OtherField,
       (SELECT ObjFieldOne__c, ObjFieldTwo__c FROM CustomObj__r),
       (SELECT Name FROM Attachments)
FROM RelatedObject__c

If this is not feasible for whatever reason, then you would necessarily need to make it two queries.

2
  • Wouldn't the records being extracted be different then? – Y12K Aug 2 '18 at 3:12
  • If CustomObj had a n-1 relationship to RelatedObject – Y12K Aug 2 '18 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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