Convert Opportunity Owner during Account Owner Change [Salesforce]

Jory Dean
4 min readJun 18, 2021

When working with the Salesforce community you will find countless threads, posts, ideas, and blogs that surround productive suggestions to make a great product even better! It’s an amazing thing to see all of the solutions and ideas that come from the Community that get picked up by Salesforce and added to the roadmap. It’s a really cool thing to see Salesforce stay so close to it’s users!

Given the fact that Salesforce has thousands and thousands of ideas that are posted every single month, there are countless occasions where an idea that gets a lot of traction and points from the Community, but never come to fruition. How could Salesforce get to every single idea? It would never happen!

Tonight, I came across one of these ideas and thought to myself, there has to be a way to solve this quickly, even for those who don’t code [like me!]. The idea [posted here — https://trailblazer.salesforce.com/ideaView?id=08730000000BqqOAAS ] references a need to retain the owner of open Opportunities during the Account ownership transition. While this process should likely be handled in an APEX trigger (mass Account updates at high-volume could trip this FLOW up potentially…), for updates made in the GUI, this flow could solve a lot of the use cases pointed out in the comments. I do admit, I was a bit shocked to see how long this idea has been open for!

To get started on this solution, you want to start by building a Flow in your Salesforce org by navigating to Setup, then Flow, then new. [Please start out in a Sandbox!]

Once you select new, you should select an Autolaunched Flow with the type of “Record Triggered Flow”.

On the first node labeled “Start” you want to set up your entry criteria by selecting “Edit”. Set your flow to Trigger when a record is edited and after the record is saved.

Next, in your object setting you want to select Account with a criteria of when the Account owner is changed.

After this you want to run a “GET” step where you get all Opportunities that are Open and assigned to the new owner of the Opportunity.

The above will query only the open Opportunities assigned to the new Account owner that are listed as Open. We want to make sure we do not change owners of past closed Opportunities!

Next you want to evaluate this Opportunity GET step to make sure that your GET step successfully queried records. If you do not take this evaluation step your users will get errors when changing the Account Owner in Salesforce. You perform this with a decision element (below):

The resource above for Opportunities from “Get_Opportunity_Records” is the collection from the previous step. This step will prevent Accounts that do not have Opportunities assigned to the collection in the GET step from evaluating the next step logic in the Flow. After this step you want to Loop your records:

After your loop, you will create a “Single Record Variable” and a “Collection Variable” on the Opportunity.

Single Record Variable
Record Collection Variable

For the first step of the Loop you want to assign the “Loop” current record Id and the $Record.Prior Owner to the Single Record Variable from above (this will allow you to access the previous Account Owner ID to update on the Opportunity):

Then you’ll take this single record variable and assign it to the Record Collection variable from above:

Then attach loop back to the loop element to process the next record and finally connect to a update record step to update your new collection in the above step:

Finally, your entire flow should look something like this:

Now, once you activate your flow, viola! You should have a functional solution to test! After running this is in my test org, I can see that my Opportunity was updated to John Smith during the Account owner change process, then the flow came behind and changed it back!

Now your flow will run automatically in the background anytime an Account Owner is changed!

--

--

Jory Dean

Jory is a 5x Salesforce Certified Solution Architect at theCodery. thecodery.io