You need to sign in to do that
Don't have an account?
Girbson Bijou 8
Self Lookup relationship data
I Have a lookup relationship in to the same object ( Articles_Containers__c). The lookup field is ParentItem__c. I need to display on a VF Page All parents and Child related to them below them.
I want to make sure that the child be right after their parent (in the next line as in the attached screenshot. For Now, the visualforce launch without error but it only display the parent records, but not the child.
The Body of the VF Page
I want to make sure that the child be right after their parent (in the next line as in the attached screenshot. For Now, the visualforce launch without error but it only display the parent records, but not the child.
// Controller public class RGRPart1Controller { public Container__c container {get;set;} public Map<String,List<Articles_Containers__c>> ContainerItem{get;set;} String containerId; public RGRPart1Controller(){ container = new Container__c(); ContainerItem = new Map<String,List<Articles_Containers__c>>(); try { containerId = ApexPages.currentPage().getParameters().get('id'); container = [SELECT Id,Name,DR__c, PO__c,Arrived_Date__c, Invoice__c, Pkl__c, Description__c, Container__c.Provenance__c, Percent_Distributed__c, Bill_of_Lading__c, Size_in_feet__c, Seal_No__c, (SELECT Id,Name,Prod__c,Number__c, Number_Distributed__c,Available__c,UM__c, Quantity__c,Unit_Of_Measure_Paking__c, Pending__c, Percentagedistributed__c, Lot_Number__c ,Qty_Recieved_in_Paking_UoM__c,PrimaryDiscrepency__c,Action__c FROM Articles_Containers__r WHERE ParentItem__c = NULL ) FROM Container__c WHERE Id =:containerId]; if(container != null) { Set<Id> articleContainersParentId = new Set<Id>(); if(!container.Articles_Containers__r.isEmpty()) { for(Articles_Containers__c art :container.Articles_Containers__r) { articleContainersParentId.add(art.Id); ContainerItem.put(art.Id, new List<Articles_Containers__c>()); } } List<Articles_Containers__c> lstChildArticleContainer = new List<Articles_Containers__c>(); lstChildArticleContainer = [SELECT Id, Name, Prod__c, Number__c, Number_Distributed__c, Available__c, UM__c, Quantity__c, Pending__c, Percentagedistributed__c, Lot_Number__c, Qty_Recieved_in_Paking_UoM__c, PrimaryDiscrepency__c, Unit_Of_Measure_Paking__c, Action__c FROM Articles_Containers__c WHERE ParentItem__c IN : articleContainersParentId]; if(!lstChildArticleContainer.isEmpty()) { for(Articles_Containers__c childItem :lstChildArticleContainer) { if(ContainerItem.containsKey(childItem.ParentItem__c)) { ContainerItem.get(childItem.ParentItem__c).add(childItem); } } } } } catch(Exception e) { System.debug(e.getMessage()); } } }
The Body of the VF Page
//VF Page <apex:page renderAs="pdf" Controller="RGRPart1Controller"> <table width="100%"> <tr> <th>Record ID</th> <th>Product</th> <th>Qty Packing</th> <th>UOM Packing</th> <th>Qty revieved in packing UoM</th> <th>Qty Recorded</th> <th>Uom Recorded</th> <th>Discrepencies</th> <th>Action</th> </tr> <apex:repeat var="c" value="{!container.Articles_Containers__r}"> <tr> <td>{!c.Name}</td> <td>{!c.Prod__c}</td> <td>{!c.Quantity__c}</td> <td>{!c.Unit_Of_Measure_Paking__c}</td> <td>{!c.Qty_Recieved_in_Paking_UoM__c}</td> <td>{!c.Number__c}</td> <td>{!c.UM__c}</td> <td>{!c.PrimaryDiscrepency__c}</td> <td>{!c.Action__c}</td> </tr> <apex:repeat var="childItem" value="{!ContainerItem[c.Id]}"> <tr> <td>--{!childItem.Name}</td> <td>{!childItem.Prod__c}</td> <td>{!childItem.Quantity__c}</td> <td>{!childItem.Unit_Of_Measure_Paking__c}</td> <td>{!childItem.Qty_Recieved_in_Paking_UoM__c}</td> <td>{!childItem.Number__c}</td> <td>{!childItem.UM__c}</td> <td>{!childItem.PrimaryDiscrepency__c}</td> <td>{!childItem.Action__c}</td> </tr> </apex:repeat> </apex:repeat> </table> </apex:page>