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
SCh9SCh9 

Update Account field based on the value of a field on the most recent Renewal Opportunity of that Account


Hello,

I am looking to 
Get the most recent (closedWon) Renewal opportunity  of an Account and see if  customField (NetValue) on that Opportunity is greater than 0.

If O2 is the mose recent closedwon ContractRenewal Opp on Account 'X'. Update field "Expansion" value to 
YES  -  if  O2.NetValue  >  0
NO   -  if  O2.NetValue <= 0

("NetValue" is custom field on Opportunity
"ExpansionReduction" is custom field on Account)

Would need help with code to this problem *without using any third party app*. My approach is -
Get OppID  where MAX(CloseDate) looping through each Opp of that Account.
Trigger on Account which updates "Expansion" field on Account whenever a new Renewal Opp of Account reaches closed won 

Please correct me if I am wrong.

Thank you.
Gururaj BGururaj B
This can be achieved decleratively without any trigger or apex code. Follow the steps, please dont forget to mark as best answer if you feel so.

1. Create a Roll-up summary field on Account "RecentClosedOpty" with summarized object = Opportunity with MAX on"Close Date"
with filter criteria Stage equals "Closed Won"
2. Create a formula field on Opportunity "RcntClsdOptyOfAcc" with forumula Account.RecentClosedOpty__c
3. Create a Proces builder on Opportunity Object with Start the process "When a record is created or updated"
Definie a criteria with "Formula evaluate to true" with formula 
([Opportunity].CloseDate >= [Opportunity].RcntClsdOptyOfAcc__c && 
 [Opportunity].NetValue > 0) || 
(ISNULL([Opportunity].RcntClsdOptyOfAcc__c) && NOT(ISNULL([Opportunity].CloseDate)) && [Opportunity].NetValue > 0)

on TRUE

Add action of update record with Record = [Opportunity].Account ID
with "No critera - just update records!" set field "ExpansionReduction" to YES

on FALSE

Define a critera with "Formula evaluated to true " with formula
([Opportunity].CloseDate >= [Opportunity].RcntClsdOptyOfAcc__c && 
 [Opportunity].NetValue <= 0) || 
(ISNULL([Opportunity].RcntClsdOptyOfAcc__c) && NOT(ISNULL([Opportunity].CloseDate)) && [Opportunity].NetValue <= 0)

on TRUE

Add action of update record with Record =  [Opportunity].Account ID
with "No critera - just update records!" set field "ExpansionReduction" to NO

Activate the Proces. This should work absolutely fine.. Let me know if you have any issues.