You need to sign in to do that
Don't have an account?
Jay Sanborn
Trigger to update Opportunity after a OpportunityLineItem added - Please help
Folks
I am try to update a checkbox field on an Opportunity after I add or update an Opportunity Line Item. Here is the code:
trigger CheckConfiguration on OpportunityLineItem (after insert, after update) { String oppID; String pID; for(OpportunityLineItem oli : Trigger.new){ oppID = oli.OpportunityID; pID = 'Configuration'; if(oli.PricebookEntry.Product2.Name == pID ) { List<Opportunity> opps = [select Config_Required__c from Opportunity where Id = : oppID]; for (Opportunity oppy: opps) { oppy.Config_Required__c = true ; update opps; } } } } |
Please help and show me what I am doing incorrectly.
Thank You
Jay
Try out the given code :
trigger CheckConfiguration on OpportunityLineItem (after insert, after update)
{
String oppID;
List<Opportunity> opprt= new List<Opportunity>();
for(OpportunityLineItem oli : Trigger.new)
{
oppID = oli.OpportunityID;
if(oli.PricebookEntry.Product2.Name == 'Configuration' )
{
List<Opportunity> opps = [select Config_Required__c from Opportunity where Id = : oppID];
for (Opportunity oppy: opps)
{
oppy.Config_Required__c = true ;
opprt.add(oppy);
}
}
}
update opprt;
}
Hope this helps.
One more modification,
Thanks,
Bala