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
Ganesh HembramGanesh Hembram 

Creating new record from related List using apex code

Hello developers,

how to create or add new record from related list using apex code. If possible then give some sample code.

Thanks
sandeep sankhlasandeep sankhla
Hi Ganesh,

Can you elaborate little more what exactly you want .

Yes , you can have a button on related list and there you can create as amny child records you want from apex...

Thanks
sandeep
Ganesh HembramGanesh Hembram
Hello sandeep sankhla,

User-added image
check the image above, suppose i'm creating "New Job Application" from Candidate related List and the record will save in the "Job Application" Object. or the record is inserted in the "Job Application" Object.

User-added image
but i want the same process using apex code which will create "New Job Application" from Candidate related list and it will insert or save the record in the "Job Application" Object.
sandeep sankhlasandeep sankhla
Hi Ganesh,

If it is already there , then you want same thing from apex..is it that you want to do some additional things in apex before inserting the job application ??

Thanks
Ganesh HembramGanesh Hembram
Yeah.. Sandeep Sankhla, exactly i want the same using apex.
sandeep sankhlasandeep sankhla
Hi Ganesh,

So you want to use your custom VF page on clcik on that button correct? if this is the case then simply you can create a list button in your objct and there you can select VF page so whenever you click on that button you rvf page which launch , from there you can give the layout which you need and based on that user can enter the records...

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer