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
telnexttelnext 

VisualForce and Controller: how to manage parent-child relatioship

Dear All,  I have two Custom Object. Say those as Parent__c and Child__c. Obviously Child__c has a lookup relation to Parent__c object (I am considering here custom object, but my question is general and it is valid also on standard objec like Account and Contact).  I would like that from a VisualForce page  a user can create a Parent__c record an many related Child__c object (the latters like a table where I can add/remove rows). When I click on the custom button Insert then the Parent__c and Child_c objects are saved ion the SalesForce DB. I am able to reproduce this using my Custom Extension. I set on the visualforce page as standardController = "Parent__c" and as extensions="MyExtension".  However, to achieve this what I have done is also to manage on the extension a separate List<Child__c> and so, when I add/remove a row from the table in the visualforce page I add/remve an element from that list. Then when I click on Insert Button I call a method in the extension that before save the Parent__c object, then set the id of the Parent__c object just created in all the Child__c element of the list and finally insert also the list.  I would like to know if there is a way to do not use a my List<Child__c> in the extension, but directly use the Parent__c.Child__r list to add/remove Child_c objects (rows). In this way then can I use the standard save method of the Parent__c standard controller to save the Parent__c object and all the related Child__c element that are in the Parent__c.Child__r list (like a CASCADE in all child)? I have tried to achieve this, but when I try to add/remove element from the Parent__c.Child__r list it is like the element are not added to the list (the list is always empy).  BR