+ Start a Discussion

Need Help to Insert New Records using APEX

I am trying to "copy" a custom object and four related lists into another custom object and four similar related lists.  Not all of the fields would be copied; only a select few.


Does anyone have any sample code that they can offer which will serve as a starting point?


The use case would be as such:


On the Tab for Object_A, there will be a command button to initiate the "Copy" process.  Object_A.Name and several fields would be used to create a new record in Object_B.  Object_A has a related list for which all the records need to be copied to a related list for Object_B (there are actually four of these related lists).



Best Answer chosen by Admin (Salesforce Developers) 

Hi ,


you should call  action={!yourMethodinClass} in <apex:page /> tag.

you cant use DML in constructor.


I think the button on Object A will pass the Id of Object A record , then you would call Intermediate page where you will do whole development. then Pass the page reference to new created object.that will send you to new Record of object B.



I think it may help you .