+ Start a Discussion
Oscar Hernandez 18Oscar Hernandez 18 

Apex Trigger to update Account field based on date last Opportunity was created

I'm trying to auto update a field on my accounts based on the last time a new opportunity was created for that account and on the account's annual revenue.  For example, account A has annual revenue greater than $250 million and hasn't had a new opportunity created in 2 months.  At the two month mark of no new opportunities, I'd like to update the account's "rating" field to a certain picklist value.  If the same account reaches the 4 month mark, I'd like to update the "rating" field again to a different picklist value.  If the account does not meet the annual revenue criteria (say it was under the $250 million threshold), then the trigger ignores it.  Any suggestions?  I'm new to triggers and apex code so would appreciate any help.  Thanks!
Dhanraj Poojary 18Dhanraj Poojary 18
Basically you will need to write the trigger on Opportunity Object with events of After Insert and After Update.
IF you need more help on coding part then ping me back.