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.

1 Answer 1

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
    Commented Aug 2, 2018 at 3:12
  • If CustomObj had a n-1 relationship to RelatedObject
    – Y12K
    Commented Aug 2, 2018 at 3:19

You must log in to answer this question.

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