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
NimaNima 

Insert data in multiple related object from one page

I have two custom objects for example xx__c and yy__c.

yy__c is the detail object and xx__c is the master object.

 

I would like to create a VF page and insert record to both xx__c and multple  yy__c when i click on the save action.

I also want to launch this VF page using a button from  Campaign detail page.

 

Does anyone have any sample code for this?

 

Thank you 

Karthikeyan JayabalKarthikeyan Jayabal

Refer to the below Apex doc link for the sample code to

Create Parent and Child Records in a Single Statement Using Foreign Keys : 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/langCon_apex_dml_foreign_keys.htm?SearchType=Stem

 

Other considerations:

  1. Campaign standard controller should be used (in order to link it with a Campaign detail page button)
  2. An external ID field should be created at the master (parent) custom object to use the above sample code
  3. Controller extension should have the action method which performs the Database.insert operation
NimaNima

Thank you Karthikeyan for the reference. I will look into it.