I want to select the fields name__c and description__c from my CustomObject along with the attachments from the attachment object.
Can I do this with my query below? What should i write in my inner select clause ParentId = Id?
public List <CustomObject__c> getTestList() {
List <CustomObject__c> TestMSList = [SELECT Name__c, Desrciption__c, (SELECT Name FROM Attachment WHERE ParentId = Id) FROM CustomObject__c];
return TestList;
}
Best Answer
There are two methods to achieve your task.
Utilize
StandardController
controller provided by salesforce. This allows you to<apex:relatedList>
which displays the relatedlist of any particular record. For example, if you're implementingstandardcontroller
forAccount
then for a particular record ofAccount
it will display it's related list such as Contacts, Opportunities etc.Fetch the record along with it's related list. Just the way as @AlexanderBerehovskiy highlighted.
Method 1
Method 2
VF Page:
Apex Controller: