You need to sign in to do that
Don't have an account?
Jay reddy
Apex to create multiple child records when a parent record is created
Heya mates,
I'm trying to create multiple child records with the help of apex, when the parent record is created. My issue is there is picklist field on Child object with 20 values and when we create a parent record, the apex should create 20 different child records based on the picklist value on child object.
OBJECTS: CustomObjA, CustomObjB [Masterdetail]
I know below code is very ametuer, which explains my range in apex coding. Also, the code should be builkfied.
I'm trying to create multiple child records with the help of apex, when the parent record is created. My issue is there is picklist field on Child object with 20 values and when we create a parent record, the apex should create 20 different child records based on the picklist value on child object.
OBJECTS: CustomObjA, CustomObjB [Masterdetail]
I know below code is very ametuer, which explains my range in apex coding. Also, the code should be builkfied.
trigger CreateBuyingInfluence on CustomObjA (after insert) { List<CustomObjB> Childs = new List<CustomObjB>(); for(CustomObjA a : trigger.new) { CustomObjB Child = new CustomObjB (); Child.SCOP__c = a.id; Child.Name = 'testName'; Childs.add(Child); } insert Childs; }
You need to write some tthink like abobe
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
Really thanks for your help. But, actually, can we do this with just APEX CLASS instead of trigger, because I want to invoke the class from a process builder along with other actions.
Use Raj logic as is, Just add an invocable method around it,