You need to sign in to do that
Don't have an account?
Bob_z
Flow to create multiple child records
I was wondering if there is a way to create mutiple child records for an opportunity by using a number field on the opportunity record?
Below I am using this trigger to create new products, but if a user wants to add more products my code looks at that field and creates the number of product that match that number field. Iwant to give them the ability to add mor eproducts to the opportunity record if needed and I can't figure out how to update my trigger to do so that is why i am wondering if there's a way to do this with a Flow instead.
If anyone can give me advice to either update my trigger to accomadate this request or how to create that flow I would greatly appreciate it.
Thanks,
Bob
Below I am using this trigger to create new products, but if a user wants to add more products my code looks at that field and creates the number of product that match that number field. Iwant to give them the ability to add mor eproducts to the opportunity record if needed and I can't figure out how to update my trigger to do so that is why i am wondering if there's a way to do this with a Flow instead.
If anyone can give me advice to either update my trigger to accomadate this request or how to create that flow I would greatly appreciate it.
Thanks,
Bob
trigger tr_MultiProductsCreated on Opportunity (after insert, after update) { List<Yushin_Product__c> ProductRecordsFinalListToInsert = New List<Yushin_Product__c>(); If(Trigger.IsInsert || Trigger.IsUpdate) { For(Opportunity opp : Trigger.New) { If(opp.Product_Qauntity__c != null) { List<Yushin_Product__c> fetchingAlreadyExistsedRecords = [Select Id FROM Yushin_Product__c WHERE Opportunity__c =:opp.Id]; If(fetchingAlreadyExistsedRecords.IsEmpty()) { // I need to create more records if a new number is added to the field. For(Integer I = 0; I < opp.Product_Qauntity__c; I++) { Yushin_Product__c prd = New Yushin_Product__c(); prd.Opportunity__c = opp.Id; ProductRecordsFinalListToInsert.add(prd); } } } try{ If(!ProductRecordsFinalListToInsert.IsEmpty()){ insert ProductRecordsFinalListToInsert; } } Catch(Exception e){ System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage()); } } } }
Hi Bob,
Yes you can create or delete child records from flow . but what happens when user reduces count on Product_Qauntity__c
then child records should be deleted
you have to launch flow from Process builder whenever Product_Qauntity__c is changed and Product_Qauntity__c > prior value of Product_Qauntity__c
then launch a flow which creates Opportunity Child records .
2. whenever Product_Qauntity__c is changed and Product_Qauntity__c < prior value of Product_Qauntity__c
then launch a flow which deletes Opportunity Child records .
Note
you design flow but while loading data through data loader you need to disable process builder as flow doesn't handle bulk load
or else you need to start a flow such that it avoids bulk loading of data by using custom settings or custom label .
Its better to handle this scenario in Sync Triggers or Async Triggers Logic which is much better than flows.
if your org has less data then go for flow approach .
.