You need to sign in to do that
Don't have an account?
Best Approach - Automatic Record Insert
I'm just looking for a high level approach to what I want to do (i.e. do I need a Trigger or a Class, or something else).
When a user adds a certain product code to a sales order, look for associated product codes and automatically enter them in for the user.
I tried a huge trigger with many Else If statements and Insert statements. Although the code seems to compile. I can't save it to the server. Looks like I violating some governer limits.
Ideally, I'll have Product and Associated products in a table.
ProductA | ProductAQuaterlyUpdate1
ProductA | ProductAQuaterlyUpdate2
ProductA | ProductAQuaterlyUpdate3
ProductA | ProductAQuaterlyUpdate4
ProductB | ProductBSemiAnnualUpdate1
ProductB | ProductBSemiAnnualUpdate2
Any thoughts on how I go about this?
thanks for your time!
Can you post the code that compiled but threw governor limit exceptions? I can try to recommend ways to refactor the code to avoid the governor limits.
More information on Apex Coding best practices here
Thanks for looking at this. Below is the "top" part of the code...the actual code contains many more else if statements. I can post the entire code if you like.
Thanks, Paul
trigger trg_InsertUpdateProductLines on SFDC_520_QuoteLine__c (after insert) {
for (SFDC_520_QuoteLine__c obj : Trigger.new)if (obj.Product2__c == '01t500000014PepAAE') //US 5 Digit ZIP Codes (annual update)
{
SFDC_520_QuoteLine__c newLineItem = new SFDC_520_QuoteLine__c(Quote__c = obj.Quote__c, //SalesOrder Number
Product2__c = '01t500000014PeqAAE',Qty_Ordered__c = 1,
Unit_Price__c = 0);
insert newLineItem;Quote__c = obj.Quote__c,Product2__c = '01t500000014PerAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem2;}
else if (obj.Product2__c == '01t500000014PesAAE') //US 5 Digit ZIP Codes Renewal (annual update)
{
SFDC_520_QuoteLine__c newLineItem3 = new SFDC_520_QuoteLine__c(Quote__c = obj.Quote__c,Product2__c = '01t500000014PetAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem3;}
else if (obj.Product2__c == '01t500000014PeuAAE') //US 5 Digit ZIP Codes (quarterly updates)
{
SFDC_520_QuoteLine__c newLineItem4 = new SFDC_520_QuoteLine__c(Quote__c = obj.Quote__c,Product2__c = '01t500000014PevAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem4;Quote__c = obj.Quote__c,Product2__c = '01t500000014PewAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem5;Quote__c = obj.Quote__c,Product2__c = '01t500000014PexAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem6;Quote__c = obj.Quote__c,Product2__c = '01t500000014PeyAAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem7;}
else if (obj.Product2__c == '01t500000014PezAAE') //US 5 Digit ZIP Codes Renewal (quarterly updates)
{
SFDC_520_QuoteLine__c newLineItem4 = new SFDC_520_QuoteLine__c(Quote__c = obj.Quote__c,Product2__c = '01t500000014Pf0AAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem4;Quote__c = obj.Quote__c,Product2__c = '01t500000014Pf1AAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem5;Quote__c = obj.Quote__c,Product2__c = '01t500000014Pf2AAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem6;Quote__c = obj.Quote__c,Product2__c = '01t500000014Pf3AAE',Qty_Ordered__c = 1,Unit_Price__c = 0);
insert newLineItem7;}