function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
icejohn2508icejohn2508 

Create Trigger that updates an Opportunity field after the Account field has been edited/updated.

I have discovered that a workflow rule is not possible for a field update to the opportunity once the similar field is updated on the Account.  (The field on the Opportunity only exists on a unique record type so no other Opps would be updated).  Is there a simple trigger that can be created to accomplish this?

 

Our support team currently is tasked to update the field on the Opportunity which is tied to a workflow rule/field update that updates the associated field on the Account. Our Sales Manager would like the Sales Team to update the similar field on the Account and thus the Opportunity field would also get updated in the event the support team forgets to update the field.

 

The field name is: Clearing Account Status and it has three values:

 

Demo Account 

Production Account

Demo and Production Account

 

 

Thanks for any assistance.

wt35wt35

Is your field meant to have always the same value as the one on the account ?

If so, there is way simpler by creating a cross-object formula

 

icejohn2508icejohn2508

Yes.  Is they choose Demo Account on the Account record it should be Demo Account on the Opportunity.

RocketRocket

Below is the trigger which which updates a field on the opportunity object in response to any update done oin the

account object 

 

 

Trigger Modified on Account (before update) {

set<id>ids=new set<id>();
for(account acc:trigger.new)
    {
      ids.add(acc.id);     
    }
    
 
 
list<opportunity> k=new list<opportunity>();
   
    if(ids.size()>0)
    {
    
     list<opportunity>opp=([select id,name,nextstep from opportunity where accountid in:ids]);     
     
     for(opportunity opplast:opp)
         {
         
             opplast.nextstep='Move Ahead';
             k.add(opplast);
         
         }
     
    
    
    }
 update k;   
}

 

 

 

 

 

icejohn2508icejohn2508

Thanks Rocket.  I am very new to creating triggers and I am not exactly sure where the field name and values need to be added in the code.  Also,will I have to have a seperate trigger for each of the three values in the picklist (similar to a workflow rule).

 

Field Name = Clearing Account Status

Values= Demo Account, Production Account, Demo and Production Account

 

John