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
Luciano RobertoLuciano Roberto 

Visualforce to create record child

Hi Folks,

I have two objects:
ParentObject__c (Parent record)
ChildObjetc__c (Child Record)

The relationship between them is master-detail.

I need to create a visualforce page to be able to create a child record, that is, when accessing the details of the parent record, have a custom button that will call the visualforcepage to be able to create a child record, with the parent record id.
Does anyone have any idea code to help me?

Best Answer chosen by Luciano Roberto
NehaDabas16NehaDabas16
Hi Luciano,

If you just want to create child record from parent detail page, I would suggest you to use quick actions instead of a custom button and visualforce page, unless you have some other requirements to go with custom page solution which you have not stated here.

Follow below steps to achieve this:
  1. Go to parent object from object manager and click on " Buttons Links and Actions" Link.
  2. Then create a new action with action type = "Create a new record". Select target object as your child object and then define other properties.
  3. Then select the fields of child object that you want on the record creation page. Click save.
  4. Go to the page layout of parent object and add the newly created action to quick actions bar.
Please like and mark resolved if this helps.
 

All Answers

NehaDabas16NehaDabas16
Hi Luciano,

If you just want to create child record from parent detail page, I would suggest you to use quick actions instead of a custom button and visualforce page, unless you have some other requirements to go with custom page solution which you have not stated here.

Follow below steps to achieve this:
  1. Go to parent object from object manager and click on " Buttons Links and Actions" Link.
  2. Then create a new action with action type = "Create a new record". Select target object as your child object and then define other properties.
  3. Then select the fields of child object that you want on the record creation page. Click save.
  4. Go to the page layout of parent object and add the newly created action to quick actions bar.
Please like and mark resolved if this helps.
 
This was selected as the best answer
Luciano RobertoLuciano Roberto
Thanks NehaDabas16,


My problem was more or less in this context that you mentioned. I managed to resolve by following his steps.
Thank you very much.