You need to sign in to do that
Don't have an account?
utz1
Code is giving error of recursive call
Hello,
I am creating invoice lie item same as quote line item. My code is giving error of recursive call. can someone help me with this.
trigger CreateInvoiceLineItem on Invoice__c(after insert, after update) {
/* This Trigger Creates Invoice Line Item. Invoice Line Item will be Same as Quote Line Item
We need to set pricebook for Invoice
Ref: https://developer.salesforce.com/forums/?id=906F00000008llQIAQ */
Invoice__c inv = trigger.new[0];
system.debug('List of Invoice:'+inv);
// Fetch Quote Id for Invoice
Quote oppId = [SELECT AccountId, Id, Pricebook2Id FROM Quote where id=:inv.Quote__c];
system.debug('Quote Ids '+oppId);
// Fetch Quote Lines
List<QuoteLineItem> opplines=[select id, quantity, PriceBookEntry.Product2Id ,UnitPrice,PriceBookEntry.Pricebook2Id
from QuoteLineItem where QuoteId=:oppId.id];
system.debug('List Of Quote Line Item '+opplines);
// Loop Opportunity Lines
for(QuoteLineItem oppline:opplines){
// Create Order Line Object
Invoice_Line_Item__c OrderLine = new Invoice_Line_Item__c();
OrderLine.Invoice__c= inv.Id;
//OrderLine.Product2Id = oppline.PriceBookEntry.Product2Id;
OrderLine.Quantity__c = oppline.Quantity;
//OrderLine.PriceBookEntryId = oppline.PriceBookEntryId;
OrderLine.Unit_Price__c = oppline.UnitPrice;
//oppline.PriceBookEntry.Pricebook2Id
insert OrderLine;
}
}
thanks & best regards,
utz
I am creating invoice lie item same as quote line item. My code is giving error of recursive call. can someone help me with this.
trigger CreateInvoiceLineItem on Invoice__c(after insert, after update) {
/* This Trigger Creates Invoice Line Item. Invoice Line Item will be Same as Quote Line Item
We need to set pricebook for Invoice
Ref: https://developer.salesforce.com/forums/?id=906F00000008llQIAQ */
Invoice__c inv = trigger.new[0];
system.debug('List of Invoice:'+inv);
// Fetch Quote Id for Invoice
Quote oppId = [SELECT AccountId, Id, Pricebook2Id FROM Quote where id=:inv.Quote__c];
system.debug('Quote Ids '+oppId);
// Fetch Quote Lines
List<QuoteLineItem> opplines=[select id, quantity, PriceBookEntry.Product2Id ,UnitPrice,PriceBookEntry.Pricebook2Id
from QuoteLineItem where QuoteId=:oppId.id];
system.debug('List Of Quote Line Item '+opplines);
// Loop Opportunity Lines
for(QuoteLineItem oppline:opplines){
// Create Order Line Object
Invoice_Line_Item__c OrderLine = new Invoice_Line_Item__c();
OrderLine.Invoice__c= inv.Id;
//OrderLine.Product2Id = oppline.PriceBookEntry.Product2Id;
OrderLine.Quantity__c = oppline.Quantity;
//OrderLine.PriceBookEntryId = oppline.PriceBookEntryId;
OrderLine.Unit_Price__c = oppline.UnitPrice;
//oppline.PriceBookEntry.Pricebook2Id
insert OrderLine;
}
}
thanks & best regards,
utz
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger CreateNewQuote caused an unexpected exception, contact your administrator: CreateNewQuote: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateInvoiceLineItem: maximum trigger depth exceeded Opportunity trigger event AfterUpdate for [0068E00000Bivlw] Invoice trigger event AfterInsert for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS] Invoice trigger event AfterUpdate for [a0Q8E000001oYhS]: []: Trigger.CreateNewQuote: line 42, column 1