This is my Pseudocode

Trigger on Territory2 before Update
If  IsChanged (UserTerritory2Association.User) 
Get AccountID of the Account assigned to the Territory from ObjectTerritory2Association
Get UserId of the Territory's Assigned Owner from UserTerritory2Association
Fetch Child Records related to the AccountID  from Account 
Add the Child Records to a List
For EachItem in the ChildRecordList Get the ownerid 
childrecordOwnerid = Territory's new Assigned OwnerID

Problem Definition:

There is a a self relationship on Account object

  • Parent Record: Account 1, RecordType = HQ Parent

  • Child Record: Account 2, RecordType = Billing Account

  • Child Record: Account 3, RecordType = Billing Account

On Account2, and Account 3 I have a field called Parent that looks up to Account 1

So basically I want to update the owner on the child records to be the user who is assigned to a Territory in the Territory Model.

The child records don't have a direct relationship with Territory2.

Since there is an additional relationship involved, Is this possible in a trigger or a flow ?


Added relationship diagram

If Assigned User in Territory2 is updated from 'David Yee' to 'Fred Smith' , All the Billing Accounts should be updated to 'Fred Smith'

enter image description here

Can i create a flow or trigger on the Territory2 Object such that when the assigned owner is updated, the owners on the Billing Account are updated. The owner on the HQ Account will be the same.

  • so - yes, it is possible in either flow or trigger and if I understand you right, you just want child Accounts to have same owner as parent, conceptually you could break this into two flows/code units - changing account owner based on territory association and then changing all children owners based on change in parent owner
    – cropredy
    Mar 31, 2022 at 0:31
  • I don't want child Accounts to have same owner as parent. I want child Accounts to have owner who is assigned the Territory. Mar 31, 2022 at 2:17
  • 1
    as long as you can query for the Parent accounts, the flow or trigger can query and update the child accounts. The issue you'll run into is if upon a territory assignment change, there are thousands of parent accounts with 1+ child accounts. You could run into Limits issues unless you delegate to queueable or batchable
    – cropredy
    Mar 31, 2022 at 3:53


You must log in to answer this question.