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
Jay16Jay16 

Create multiple child records from parent button

Hi, 

I could really use some guidence on a current problem I'm faced. Any help would be much appreciated.

I have 2 custom objects with a master detail relationship: parent__c and child__c. 

A Parent__c record  contains information for 4 payments. Chilld__c will be the recipt for each individual payment. 

What I want is for a user to be able to press a button on the parent and create 4 new child records. Each child record will be a recipt for one of the 4 payments.

Can anyone tell me how this can be achieved?

So far I've seen similar examples using Apex, Flows, Custom Controllers, VF pages and more. All of them are fine, I just don't know which would be most appropriate. 

Thanks in advance. 
Best Answer chosen by Jay16
ShashForceShashForce
Hi,

The most appropriate approach is to create a visualforce page with standard controller as parent__c and add a controller extension class which performs your operation of creating 4 child__c records. Then, create a custom button with this visualforce page as the content. Here is an example of the extension: http://salesforce.stackexchange.com/questions/27360/create-a-button-in-vf-page-that-creates-a-new-case-with-certain-record-type

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank

All Answers

Ankit AroraAnkit Arora
I would've gone with JS button with AJAX toolkit where you can directly call the apex class and insert the records on child.
ShashForceShashForce
Hi,

The most appropriate approach is to create a visualforce page with standard controller as parent__c and add a controller extension class which performs your operation of creating 4 child__c records. Then, create a custom button with this visualforce page as the content. Here is an example of the extension: http://salesforce.stackexchange.com/questions/27360/create-a-button-in-vf-page-that-creates-a-new-case-with-certain-record-type

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank
This was selected as the best answer
Bindhyachal Kumar SinghBindhyachal Kumar Singh
Hi Jay16,

You can write an apex class and create 4 child record in this class. Create a custom button on parent object with created apex class.
Jay16Jay16
Hi guys, 

Thanks for your help with this. Much appreciated.