Some of my Accounts are known as Ultimate Parents. They are either parent or grandparent to all other Accounts for a particular company. Due to a large data migration, I would like to have the Ultimate Parent name in a field (UPName__c) on every Account. Unfortunately, this was not done when the system was initially put together, so I now must somehow put together a way to scan through all of my Accounts and get that information.
Ultimate Parent accounts have a checkbox checked to indicate they are an Ultiamte Parent (UltimateParent_c = "Yes"). So I'm thinking I would need to query the ParentAccount_r.UltimateParent_c of every Account record and if the UltimateParent_c = "Yes" then I would grab the Name field and put it into my UPName__c field.
Somehow I have to account for grandchildren accounts. Their ParentAccount will not be the Ultimate Parent, so I don't know how to obtain the Ultiamte Parent name. I'm guessing I would need to put together a query and run it a bunch of times, with the following runs checking to see if the Parent Account has UPName_c field populated, and if it does to grab the value and put it in the current Accounts UPName_c field...?
How would I go about doing this ? Will it be code which would be run in the developer console ?
Thank you very much for any help you can give. I greatly appreciate it.