+ Start a Discussion
prati@salesforceprati@salesforce 

Creating multiple child records while creating parent record based on some Criteria, using trigger

Hi,
I want to create multiple child records while creating a parent record using an afetr insert , after update trigger but I have few questions. So lets say parent object is A and B is child object. There are like 36*3 fields on A. out of them 36 fields are Yes/No picklist fields and 36 fields are multiselect picklists. What I want to do is when user selects No in any or all of the fields, it should create those many numberr of child records B. Also when user selects No as value then they need to select some values from multiselect picklists too, Based on that the child object B has fields which should be populated with values in the parent object.
     Please provide me with some ideas on how I can proceed?

Thank you
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
First, I would fetch all the fields on object A using Describe sObject and then iterate over the record in trigger.new, pass the field name and get the value. If the value is No then I will create a child record using the values from parent record in trigger.new.
sathishkumar periyasamysathishkumar periyasamy
Prathi, When you change value from YES to NO (OR) Null to NO then you need to create child record for how many field has "NO" field. can you please confirm this scenario - First picklist value changed from "YES to NO" and system created child record, now updating same record from "NO to YES" - do you want to delete the existing child or not?
prati@salesforceprati@salesforce
Hi 
Here Once it is No , child record should get created , even if it is changed to Yes later, we dont delete it. Once The record is saved, we are not deleting it.
sathishkumar periyasamysathishkumar periyasamy
Prati, I would recommend to use flows to create child record's based on parent object information and call that flows inside process builder. Please let me know if you need any help to create flows and process builder.
prati@salesforceprati@salesforce
Hi
I had already tried using flow but i couldnt figure out the errors, as it is very difficult to debug them. Here is the link
https://success.salesforce.com/answers?id=9063A000000ZrpB
Thank you