function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PFangPFang 

Creating a Visualforce page with a table of related child records

Hi Guys,

 

Hope we're all doing good!

 

I'm in the process of creating a Visualforce page with related child records arranged in a table but I'm not able to edit any of their fields or create new records. The parent object is called Bill of Lading while the child object is called Skids, it's like your opportunity to opportunity product/line item relationship wherein the Bill of Lading has child skid records. I will be posting both screenshot links of the page along with code snippets that may aid in my query on creating, editing child records on a Visualforce page, many thanks!
 

Screenshot - top section with parent object:

http://screencast.com/t/tTnX7DWGu

 

Screenshot - child record table:

http://screencast.com/t/ghfr1m9Ga

 

Non-working Visualforce code:

 

<apex:pageBlock >
<apex:pageblockTable title="Bill_of_Lading__c" value="{!Bill_of_Lading__c.Skids__r}" var="BOL">
<apex:dataTable value="{!Bill_of_Lading__c.Skids__r}"
                      var="BL"
                      cellPadding="4" border="1">    
       <apex:column headervalue="{!BOL.Dimension__c}">
       {!BOL.Dimension__c}
       </apex:column>
       <apex:column value="{!BL.Number_of_Pieces__c}">
       </apex:column>
       <apex:column >
            {!BL.UOM__c}
         </apex:column>
       </apex:dataTable>
 </apex:pageblockTable>
</apex:pageBlock>

</apex:form>

<apex:detail relatedList="false"/>
  <apex:relatedList list="Skid__c"/>

</apex:page>

 Draft extension:

    public List<Skid__c> getSkids()
    {
       if ( (null!=getBillofLading().id) && (skids == null) )
       {
           skids=[SELECT Id, Name, Bill_of_Lading__c, Dimension__c, Number_of_Pieces__c, UOM__c, Weight__c
                         FROM Skid__c
                         WHERE Id =: getBillofLading().id
                         ORDER BY CreatedDate];
       }                           
       return skids;
    }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I wrote a blog post some time ago around editing a record and its children in a single page.  This should be straightforward to adapt to your requirements I think:

 

http://bobbuzzard.blogspot.co.uk/2011/04/edit-parent-and-child-records-with.html

All Answers

bob_buzzardbob_buzzard

I wrote a blog post some time ago around editing a record and its children in a single page.  This should be straightforward to adapt to your requirements I think:

 

http://bobbuzzard.blogspot.co.uk/2011/04/edit-parent-and-child-records-with.html

This was selected as the best answer
PFangPFang

Thanks Bob, will take a look  :)

PFangPFang
Was able to recreate this and I'm hoping that this applies to the related list table I have on our VF page
PFangPFang

Played around with your parent child code and confirmed it's applicable to our form table, thanks heaps bob!