I have a triggerHandler on the Opportunity object which inserts other objects on afterInsert if it meets the criteria (Opportunity Line Item and Payment). The objects are added to a list before inserting but when the first list is inserted the next list is emptied/nulled so nothing is being inserted on the next list.
The instantiation of the lists looks like this:
static List<Membership__c> membershipsToUpdate;
static List<Case> casesToUpdate;
static List<OpportunityLineItem> oppItemsToInsert;
static List<npe01__OppPayment__c> paymentsToInsert;
public TRG_OpportunityHandler(){
membershipsToUpdate = new List<Membership__c>();
casesToUpdate = new List<Case>();
oppItemsToInsert = new List<OpportunityLineItem>();
paymentsToInsert = new List<npe01__OppPayment__c>();
}
And the inserts look like this:
if(paymentsToInsert.size() > 0) {
insert paymentsToInsert;
}
if(oppItemsToInsert.size() > 0) {
insert oppItemsToInsert;
}
if(membershipsToUpdate.size() > 0) {
update membershipsToUpdate;
}
if(casesToUpdate.size() > 0 ){
update casesToUpdate;
}
If I switch place and insert oppItemsToInsert before paymentsToInsert then oppItems are inserted but not payments. Is it really not possible to do 2 DML transactions in one trigger? How else can I do this?
oppItemsToInsert
andpaymentsToInsert
get filled? We've seen part of your trigger handler, but what does the trigger itself look like?