You need to sign in to do that
Don't have an account?
MontTwo MontTwo
Insert 2 objects (parent and child) at a time (over 200 records)
Hello. I have over 200 records, and I need to insert 2 lists. Work's records are created too fast and can't take a customField from still nott inserted Case. If insert 1 per time - Error: Too many DML statements: 151.
My code:
My code:
public class Helper { public static void upd(Map<Id, Case> cases){ List<Case> newCases = new List<Case>(); List<Work__c> wp = new List<Work__c>(); for(Case c1 : cases.values()){ Case c2 = new Case(Origin = 'Web', Status = 'New'); newCases.add(c2); for(Work__c w1 : [SELECT Id, Quantity__c, Custom_Field__c FROM Work__c WHERE Custom_Field__c =: c1.Id]){ Work__c w2 = new Work__c (Quantity__c = w1.Quantity__c, Custom_Field__c = c2.Id); wp.add(w2); } } insert newCases; insert wp; } }
All Answers