You need to sign in to do that
Don't have an account?

Trigger on OpportunityLineItem to Update Field on Opportunity
I have gotten myself turned around on this trigger and can not figure out how to get it right. I have a custom field on the OpportunityLineItem / Opportunity Product that has the Length of Months that the product will be used for called Number_of_Months__c. I need to update the Opportunity in a field called Contract_Length_Months__c with the maximum date of all the products when a customer enters it.
I would appreciate any help in pointing me in the right direction:
At the line:
I get the following error from the Developer Console IDE : "Variable does not exist: contractLenghtMonths"
Thank you in advance for any help.
Robert
I would appreciate any help in pointing me in the right direction:
trigger OpportunityLineItemTrigger on OpportunityLineItem ( after update) { List<Id> oppIds = new List<Id>(); Decimal contractLengthMonths = 0; if(trigger.isAfter) { for (OpportunityLineItem oli3: trigger.new){ oppids.add(oli3.opportunityId); }//END for (OpportunityLineItem oli3: trigger.new) List<OpportunityLineItem> allOLI = [SELECT id, Number_of_Months__c FROM OpportunityLineItem WHERE OpportunityId in: oppids]; List<Opportunity> oppsToUpdate = [SELECT id, Contract_Length_Months__c FROM Opportunity WHERE id in: oppids]; if(allOLI.size() > 0){ for(OpportunityLineItem allOLI2: allOLI){ if(allOLI2.Number_of_Months__c > contractLengthMonths){ contractLengthMonths = allOLI2.Number_of_Months__c; }//END if(allOLI2.Number_of_Months__c > contractLengthMonths) } //END for(OpportunityLineItem allOLI2: allOLI) for(Opportunity oppUpdate: oppsToUpdate){ oppUpdate.Contract_Length_Months__c = contractLenghtMonths; }// END for(Opportunity oppUpdate: oppsToUpdate) } }//if(trigger.isAfter) }//END OpportunityLineItem Class
At the line:
oppUpdate.Contract_Length_Months__c = contractLenghtMonths;
I get the following error from the Developer Console IDE : "Variable does not exist: contractLenghtMonths"
Thank you in advance for any help.
Robert
The error message you are getting is because a typo problem
line 18: contractLenghtMonths
line 13, 14 & 15 is contractLengthMonths
the '...Length...' is cause the problem
All Answers
The error message you are getting is because a typo problem
line 18: contractLenghtMonths
line 13, 14 & 15 is contractLengthMonths
the '...Length...' is cause the problem
Thank you, very much. Sometimes it takes a second set of eyes.
I really appreciate all your help.
Robert