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
Mike_EMike_E 

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).

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Kirtesh_JainKirtesh_Jain

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 .

 

Thanks,

Kirtesh