You need to sign in to do that
Don't have an account?
cambart14
Update Opportunity Based on Related Custom Object
I have created a custom object (Product_Brief__c) , that is related to a specific opportunity. With the Product_Brief__c there are stages (Stage_c) that can be selected from a drop down list. My Opportunity has a custom checkbox field (Submit_to_New_Products__c).
I need when the stage = "Needs Corrections/ Clarifications" that my custom checkbox field (Submit_to_New_Products__c) to be unchecked.
The code I have written is below, but it is not updating the related Opportunity.
trigger uncheckSubmitPB on Product_Brief__c (after insert, after update) { Set<ID> oppIds = new Set<ID>(); for(Product_Brief__c PB : Trigger.new) if(PB.Stage__c=='Needs Corrections/ Clarification') { oppIds.add(PB.Opportunity__r.id); } List<Opportunity> UpdateOpp = [SELECT ID, Submit_to_New_Products__c FROM Opportunity WHERE Opportunity.id IN : oppIds]; for(Opportunity ol: UpdateOpp) {ol.Submit_to_New_Products__c=false;} update UpdateOpp; }
Thanks for your help!
When you said related object... the object product_Brief__c would have a lookup to opportunity...
try this code..
trigger uncheckSubmitPB on Product_Brief__c (after insert, after update) {
Set<ID> oppIds = new Set<ID>();
for(Product_Brief__c PB : Trigger.new)
if(PB.Stage__c=='Needs Corrections/ Clarification')
{
oppIds.add(PB.Opportunity__c); //opportunity lookup field API name
}
List<Opportunity> UpdateOpp = [SELECT ID, Submit_to_New_Products__c FROM Opportunity WHERE Opportunity.id IN : oppIds];
for(Opportunity ol: UpdateOpp)
{ol.Submit_to_New_Products__c=false;}
update UpdateOpp;
}