You need to sign in to do that
Don't have an account?
Viewing Attachments by child object
Newbie!!
I'm trying to create a VF Page that displays all of a Parent's child objects attributes along with their associated attachments. My controller passes all child objects attachments into a list but my VF page displays all the attachments of every child within each childs list. We want a vf page where each child's name and accompany photo attachments are listed within their own section.
Controller:
// Throw all attachments into myPhotos list
private void fetchPhotos ()
{
myPhotos.clear (); // Empty list
for (Line_Item__c b : myChildlist) {
for (Attachment a : [Select Id, Name, ParentId, ContentType From Attachment Where ParentId = :b.Id])
{
myPhotos.add (new Photo (a.Id, a.Name, a.ParentID));
}
}
}
VF Page:
// Use nested repeat list to display attachments
<apex:repeat value="{!myChildlist}" var="it">
<apex:repeat value="{!Photos}" var="p">
<img src="{!p.url}" width="296px" height="225px"/>
</apex:repeat>
</apex:repeat>
All attachments from every line_item__c child object are displayed within every line_item__c repeat
This is because you are adding all the attachments to a single list - you'll need to use a wrapper class for this, which encapsulates a line item and its attachments. Then you would iterate through a list of the wrapper classes, and the nested repeat would iterate its list of attachments.