function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Crystal M. ReganCrystal M. Regan 

Formula for Multi-level parent relationships

Hello,

I have an Account formula field called "Finance Parent" that returns the Parent Name if there's no Grandparent or returns the highest level Parent in a hierarchy. This formula does exactly what I want it to do except one thing... if there's NO PARENT, I would like the formula to return the name of the Account itself. Any suggestions are appreciated. Here is the formula:

if (isblank(Parent.Parent.Name),Parent.Name,
(if (isblank(Parent.Parent.Parent.Name),Parent.Parent.Name,
(if (isblank(Parent.Parent.Parent.Parent.Name),Parent.Parent.Parent.Name,Parent.Parent.Name)))))
Best Answer chosen by Crystal M. Regan
Maharajan CMaharajan C
Hi Crystal,

Please try the below formula:
 
if (isblank(Parent.Name), Name,
if (isblank(Parent.Parent.Name),Parent.Name,
(if (isblank(Parent.Parent.Parent.Name),Parent.Parent.Name,
(if (isblank(Parent.Parent.Parent.Parent.Name),Parent.Parent.Parent.Name,Parent.Parent.Name))))))

Thanks,
Maharajan.C

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Crystal,

Try with below formula.
 
if (isblank(Parent.Parent.Name),Parent.Name,
    if (isblank(Parent.Parent.Parent.Name),Parent.Parent.Name,
     if (isblank(Parent.Parent.Parent.Parent.Name),Parent.Parent.Parent.Name,Parent.Parent.Name)))

If this helps, Please mark it as best answer.

Thanks!!
Crystal M. ReganCrystal M. Regan
Hello, that formula returns the same results as my orginal one. My desired outcome is that the formula returns the Account's OWN name in the field if there is no Parent. I hope that makes sense.
Maharajan CMaharajan C
Hi Crystal,

Please try the below formula:
 
if (isblank(Parent.Name), Name,
if (isblank(Parent.Parent.Name),Parent.Name,
(if (isblank(Parent.Parent.Parent.Name),Parent.Parent.Name,
(if (isblank(Parent.Parent.Parent.Parent.Name),Parent.Parent.Parent.Name,Parent.Parent.Name))))))

Thanks,
Maharajan.C
This was selected as the best answer
AnkaiahAnkaiah (Salesforce Developers) 
Hi Crystal,

Try with below formula.
If(ISBLANK(ParentId),  Owner.Username, 
   If( ISBLANK(Parent.ParentId),Parent.Owner.Username,
      If( ISBLANK(Parent.Parent.ParentId),Parent.Parent.Owner.Username,
         If(ISBLANK( Parent.Parent.Parent.ParentId ),Parent.Parent.Parent.Owner.Username,
           If(ISBLANK(Parent.Parent.Parent.Parent.ParentId),Parent.Parent.Parent.Parent.Owner.Username,Parent.Parent.Parent.Owner.Username )))))

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
Crystal M. ReganCrystal M. Regan
Thank you both for the feedback. Maharajan's formula worked like a charm. Have a wonderful night to you both.