11 respuestas
I got what you mean, some the trigger is on OLI, and need to update field on Opportunity, right? Here is the code:I'm not sure what's your exactly case here, so you may need to modified a little , like what's the relation key between OLI and Opportunity...Let me know if you still have any questions~trigger FulfillmentTrigger on OpportunityLineItem (after insert, after update, after delete) { Map<Id,OpportunityLineItem> OLIids = new Map<Id,OpportunityLineItem>(); List<OpportunityLine> updateCheckBox = new List<Opportunity>(); for(OpportunityLineItem oppLI: Trigger.new) { OLIids.put(oppLI.OpportunityId,oppLI); } /*What's the relation key between opportunity and OLI ? / You have to change something after 'where' / For example, if oppLI.OpportunityId= the Id of a Opptunity? */ List<OpportunityLine> oppLIo = [SELECT Id, Fulfillment_Instructions_Status__c from OpportunityLineItem where ??? = : OLIids.keySet()]; for(Opportunity oli: oppLIo ) { String test = OLIids.get(oli.OpportunityId).Fulfillment_Instructions_Status__c; if(test.contains('QFF Submitted')) { Opportunity o = new Opportunity(id=oli.OpportunityId); o.Fulfillment_Instructions_Complete__c = true; updateCheckBox.add(o); } else if(test.contains('Case Created')) { Opportunity o = new Opportunity(id=oli.OpportunityId); o.Fulfillment_Cases_Created__c = true; updateCheckBox.add(o); } } if(updateCheckBox.size()>0) update updateCheckBox;}