Thanks to the Spring 21 Salesforce release, you can now easily see what the Prior Value of a field was in Salesforce using a Flow instead of Process Builder. Interested to see who the prior owner of an account was in Salesforce? This is the perfect solution to make that information visible!
Join Cory as he shows you exactly how this works:
VIDEO TRANSCRIPT:
Hi, this is Cory with Cloud Adoption Solutions, and today I’m going to be going over how to use the new record prior value variable and record triggered flows. So in the Spring 21 release, Salesforce is giving us access to the prior value in flows, which is really nice because previously, we used to have, we had to use Process Builder to check the prior value. And then you could launch a flow based on that. With the access the prior value in flows, it gives us a lot more flexibility allows us to move away from process builder and continue to move towards flow since it’s easier to build with.
So to set the stage here, I have my dev org. And I have this prior owner field on the account, and it’s a lookup to the user. And I also created a prior owner field on the contact. And for this example, all I’m doing is I want to store the prior owner if the owner if the owner is changed, and I want to store that in this prior owner field. And likewise, with the contacts, if the owner of the account changes, I want to store the prior owner on that prior owner field on the contact. So to go into Flow Builder. So I made an after save flow when the record is created or updated on the account object.
And a little note here, you can’t check prior value on this on the Start object on the flow. But what you can do is check it in the very first decision element. So I’m letting this run with no conditions. So anytime an account record is created or updated, it’s going to kick off this flow. And then I have a decision element. And here I’m checking to see if the owner ID changed. So what I’m looking at here is the the owner ID of the record of the account record and does not equal the prior owner ID. So this is the new variable that Salesforce gives us access to. So this record prior is the value before the record was saved. So again, just checking to see if the owner changed, basically. And if it did change, then I want to get the related contact records. So standard lookup here and filtering it on the account ID. So if the contacts account ID equals the records account ID, I’m going to grab those contacts, I’m getting all the records, because I want to change that field on all of them. And then just checking to see if the contacts if contact records are found, because if not, I don’t want to loop through them. So if I find these contact records, I’m going to loop through them. And then I’m going to assign the current item from the from the loop. So the current contact record. The current contacts record owner ID Sorry, I’m going to assign that to the prior value of the account records owner ID.
So record prior here is the prior account before it was saved that owner ID. And then standard way of adding a record to a loop, I created a new collection variable called contact collection. And then I’m adding the current item to that. So it’ll loop through there for all the contacts that it found. Then after the last item, I’m going to update those contacts. So just a standard update with my contact collection variable. And then I’m going to assign the prior owner field to the account. And then I’m going to update the account record. And then I say have been activated that I’m going to go back to my account record here and I’m going to change the owner from myself to this test user that I created. And as you can see it updated this prior owner field And then if I go look at the contact records, nothing’s here right now, because I didn’t refresh. So I’m going to refresh this page. And then we have the new owner, and then the prior owner. And we want to check the other.
So this account has three contacts. So I’m going to check the other ones. So here, the prior owners updated. And one more, make sure this one changed. And this one changed also. So obviously a simple example there, but it shows you the new the new prior value features of Salesforce, and it’s really cool that they’re giving us access to this prior value. I’ve been wanting it for a long time. It’ll really help when we’re building automation. And if you need help building on it, automation, feel free to contact us. Our contact info is at the end of this video. Thanks and have a nice day.