0

Business Need: We have some custom fields on Account records that need to be populated based on field values of the most current Contract record related to the Account. These are the custom fields on the Account

  • Latest Contract - Lookup Relationship that pulls from Contract ID Latest Contract
  • Start Date - Date field that pulls from Contract Start Date Latest
  • Contract End Date - Date Field that pulls from Contract End Date
  • Latest Contract Status - Test field that pulls from Contract Status
  • Latest Contract Term (months) - Number field that pulls from Contract Term

I built a Record Triggered Flow that updates these fields when a Contract is record created or updated.

Problem: These fields are being modified when any Contract related to the Account is updated. For example, if an older Contract related to the Account is modified, the custom fields on the Accounts update to the information on the older contract.

Is there a way I can modify the flow to only look at the most current Contract related to the Account, and update the Account fields when the most current Contract fields are updated? If I configure the trigger to run when a record is created, it pulls the latest Contract created. However it only updates the Account field values to the values on the Contract fields at the time of creation

Below are pics of the flow I built:

enter image description here enter image description here enter image description here

Thank you so much for your time and consideration!

1 Answer 1

0

For this one I think you are right that you want a record triggered flow that runs after a contract record has been created or updated.

What you will need to do is add in some more logic to that flow. You will want to have a record get where you get all of the other contracts that are linked to the same account record as the triggering contract.

Then in the flow test on the returned collection of contract records, possibly looping through them and for each one testing if the item in the loop is newer than the contract record that triggered the flow ( ie have a decision in the loop of the flow that tests if the item in the loop was is "newer" than the contract).

You will want a Boolean variable in the flow outside the loop for isThisContract the latest, maybe defaulted true and then in the loop inside that decision if you find a newer one set the Boolean to false.

Finally outside the loop test on that Boolean, if after checking all the other contracts it is still true you can then update the account.

At least some approach like that. Tbh there might be a neater way of doing it in the record get for other contracts by putting in criteria saying only get other contracts that are related to the same account AND have a created date after the the contract that triggered the flow. If that is possible then its easy as you just need to check if any contracts came back. Im not sure if that kind of test is supported in a record get but I think it might be.

Either way the key is that record get of other contracts for this account in your flow.

Hope that helps!

1
  • PS this approach only works well if contract records are being created one at a time in Salesforce. If you have processes that bulk upload contracts or apis that push them in then it needs more thought still as then in one insert you could have multiple contracts under one account being inserted or updated! Commented Jan 14, 2023 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .