Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm trying to write a soql query to get all the content's ids of the related content on a custom object.

I would like to know which are the related content of a record. enter image description here

I have tried with Schema Explorer but have access to related content informations looks impossible.

Is it possible?

Other informations:

![enter image description here][2]

enter image description here

Thanks in advantage for any advice.

BR

share|improve this question

1 Answer 1

Yes this is possible with a nested SOQL query. The trick is to use the "Child Relationship Name" of the related object. You set this name when creating the lookup from the child to the parent object.

So if the parent object is Parent__c and the child is Child__c, and in the lookup from child to parent, you set the Child Relationship Name to "Children", your SOQL would look like:

SELECT Id, Name, (SELECT Id FROM Children__r) FROM Parent__c

Children__r is of type List<Child__c>. So if you were iterating through, you could do something like:

for(Parent__c p:[SELECT Id, Name, (SELECT Id FROM Children__r) FROM Parent__c])
{
    //Do stuff with the parent record p here
    for(Child__c c:p.Children__r)
    {
        //Do stuff with Child record c here
    }
}
share|improve this answer
    
Thanks Tim, the soql query format it's clear. But I don't find which is the relationship name. The objects for me are software__c(custom object), and Content (standard).Please could you help me again? –  Enry Aug 7 '13 at 16:37
    
Check your Enterprise WSDL; it'll have all of the names. Search for the section for software__c and you'll probably find it is called Content__r. –  Mike Chale Aug 7 '13 at 16:38
    
Since you are already using schema explorer, find Software__c in your schema, expand it and expand the "Child Relationships". Find the child Content relationship and expand it to see the Relationship Name. Like Mike said, it is likely Content__r unless it was changed when creating the lookup relationship. –  Tim Smith Aug 7 '13 at 16:55
    
Looks impossible query the related content file, i have updated the question with the wsdl and the schema explorer screenshots.Please take a look. –  Enry Aug 7 '13 at 17:04
    
Ah! I didn't notice that you were asking about the standard "Related Content" I was thinking this was a custom relationship... That "Related Content" is a different beast altogether. I don't believe you can query that relationship, although ContentDocumentLink does let you query how a document is shared with libraries and users. Sorry about that. –  Tim Smith Aug 7 '13 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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