You need to sign in to do that
Don't have an account?
Maxa
System.LimitException: Too many DML statements: 151
i Have an issue with my trigger, it is very simple one, basically it takes credit card type and expiry date from payment and put it up one level on Invoice, for reporting purposes. it works fine when a single payment is inserted however when i do bulk upload of new payments i get this error
System.LimitException: Too many DML statements: 151
here is my code below any help wpuld be greatly apreciated
trigger CC_Exp on Payment__c (after insert, after update) { Set<id> objSet = new Set<id>(); for(Payment__c objOpp:trigger.new) { objSet.add(objOpp.Invoice__c); } List<Invoice__c> myInvoice = [select Id,Status__c from Invoice__c where Id in: objSet]; for(Payment__c objOpp:Trigger.new) { for(Invoice__c objAcc: myInvoice) { if (objOpp.Payment_Method__c == 'Credit Card') { { objAcc.CC_Expiry_Date__c = objOpp.Expiry_Date__c;// objAcc.Creditcard_Type__c = objOpp.Credit_card_Type__c;// update objAcc; }}} }}
This is because you did not handle for the bulk insertion of records.
just take list of invoices add your invoices (which has to be updated). Do the updation out side the for loop.
list<invoice__c> lstInvs = new list<invoice__c>(); declare it below the objSet declaration
then in the for loop
objAcc.CC_Expiry_Date__c = objOpp.Expiry_Date__c;
objAcc.Creditcard_Type__c = objOpp.Credit_card_Type__c;
lstInvs.add(objAcc);
then at last update the list (outside for loops)
update lstInvs;
regards,
Shravan
i think i'm doing somethign wrong here
now i get error Duplicate ID in List, here is my trigger
It is better to check the Payment_Method__c == 'credit card' in the trigger it self.
if(objOpp.Payment_Method__c == 'Credit Card')
{
objSet.add(objOpp.Invoice__c);
}
and remove the first for loop i.e, for(Payment__c objOpp:Trigger.new)
Regards,
Shravan
if i remove the first loop it doe not let me compile, says that objOpp.Invoice__c does not exists.
i tried differnt way declaring it such as payment__c objSet;
but it tells me duplicate variables.
Can you correct me here.
Payment is Child having field on it Invoice__c which is Lookup/Masterdetail to its Parent Invoice.
thats corect payment is a child of Invoice, and i'm trying to bring up some info from apyment details to invoice level
try this:
Hope it helps.
now i get error
MISSING_ARGUMENT, Id not specified in an update call.
Give this a try:
Hi Maxa,
Sorry for the late response.
So you want to take some information from Payment and update it on Invoice.
But If there are more than one payments inserted or updated then which payment information has to updated on Invoice did you think of that?
Regards,
Shravan
I think with this logic, Invoice will be updated with only the recent payment.
is this your requirement.
Hi yes you are correct i only want mroe recent credit card info, old ones are irrelevant, with this new code i get compile error
The inner and outer selects should not be on the same object type at line 3 column 61
ohh, got it. Just change the inner query to Payment__c instead of Invoice:
thans for htat, ihave alredy played around swaping them places but get this erro
Error: Compile Error: The selected field 'Id' in the subquery and the left operand field in the where expression in the outer query 'Id' should point to the same object type at line 4 column 61
looks like catch 22 :)
Hi,
have you succeeded in solving your problem? I'm unfortunatelly facing the same issue and cannot move any forward :(
Hi.
What was the final fix in this case? I'm currently receiving a similar error where I see for a user/ org ID...
Failed to process batch for class 'BatchPaymentApplicator' for job id '7074z00007Ky901'
caused by: System.LimitException: NU:Too many DML statements: 151
Class.NU.TransactionGroupAutoNumberManager.generateNumbers: line 39, column 1
Class.NU.TransactionGroupAutoNumberManager.generateNumber: line 52, column 1
Class.NU.DueToDueFromTransactionGenerator.generate: line 53, column 1
Class.NU.TransactionGenerator2.generateTransactions: line 196, column 1
Class.NU.TransactionGenerator2.generate: line 87, column 1
Class.NU.TransactionGenerator2.generate: line 124, column 1
Class.NU.TransactionGenerator.generate: line 14, column 1
Class.BatchPaymentApplicator.createTransactions: line 507, column 1
Class.BatchPaymentApplicator.execute: line 200, column 1
Would be happy to learn where to navigate to solve this issue.