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
leanne zhang03177320069719939leanne zhang03177320069719939 

Visualforce page: Insert a Parent object and related Children objects

Hi there,

I would like to create a visualforce page that saves a single Master Opportunity with multiple Child Opportunties (Child Opportunities fields will be the same from the Master Opportunities except Account and Amount where the user can enter manually on the visualforce page).  When the user clicks on "Save" on the visualforce page, it should insert the Master Opportunity and also related Child Opportunities.

I have set up my data model. I'm using standard Opportuntiy as Child Opportunity, and has a look up field to Master Opportunity. Master Opportunitiy is a customer object which has the same fields as standard Opportunity.

I need help with the logic (controller) and I'm wondering if I could get helped on pointing in the right direction. I am thinking that in order to save Child Opportunities, the Master Opportunities should be inserted first, so that we can get the ID of the master opportunities and related to fields to save for the child opportunities. 

Thanks so much,
LZ
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Yes, you should first insert the master opp and use the id for inserting the child records. 
If you need code, please post your VF code and I can give you the controller code based on that.
LoveLaceLoveLace
I have the same problem and I can't relate the parrent Id with his Id in the child, I used a wrapper class for adding multipe row to insert childs