3 respuestas
First, don't write queries in a for loop.Second, you can save all the items needed to be updated in a list, then update them.Thirdly, if I understand correctly, you need to update Opportunity field based on the OpportunityLineItem field, right?Here is the code:trigger Projectrollup on Opportunity (after insert, after update) { Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>(); List<Opportunity> updateList = new List<Opportunity>(); for(Opportunity o : Trigger.new) { oppIds.put(o.id,o); } OpportunityLineItem[] OLI = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description, Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c From OpportunityLineItem where OpportunityId IN : oppIds.keySet() And PricebookEntry.Product2.Product_Reporting_Category__c = 'Services']; for(OpportunityLineItem o : OLI) { if(o.PricebookEntry.Product2.Sales_Order_Group__c = 'Hotline Services' || o.PricebookEntry.Product2.Sales_Order_Group__c = 'Policy Management Services' || o.PricebookEntry.Product2.Sales_Order_Group__c = 'Incident Management Services') { Opportunity opp = new Opportunity(id=o.OpportunityId); opp.Implementation_Team__c = true; updateList.add(opp); } if(o.PricebookEntry.Product2.Sales_Order_Group__c = 'ReadyTraining Services') { Opportunity opp = new Opportunity(id=o.OpportunityId); opp.Training_Team__c = true; updateList.add(opp); } } if(updateList.size()>0) { update updateList; }}***:In the first for loop, MAYBE you need to add some line like if o.HasOpportunityLineItem== true, oppIds.put(o.id,o); depends on the real situation. Let me know if you still have any questions ~^_^