0

Suppose, I have a child account as "Child Account" and it's parent account as "Parent Account" then there is one more parent account of parent account which named as " Parent of Parent Account" of child.

So, the relationship will be like: Child Account-> Parent Account-> Parent of Parent Account.

Now, I have one custom field "Corporate" on child account to be populated with the name of "Parent of Parent" Account.

Can anyone suggest the best way to populate the value of child account from parent of parent account of that child?

1
  • Just make 'Corporate' a Formula field and return Parent__r.Parent__r.Corporate__c
    – zaitsman
    Jul 23 '20 at 7:16
0

Similar to the comment on your question from zaitsman, use a formula. The formula will want to protect itself based on whether there are multiple levels, something like:

IF(NOT(ISBLANK(ParentId)),
    IF(NOT(ISBLANK(Parent.ParentId)),
        Parent.Parent.Name,
        Parent.Name),
    Name)

If I got the brackets right, the idea is to take the grandparent name if available. If there is no grandparent but there is a parent, take that name and if there is no parent use the account's own name.

3
  • I am new to Salesforce, will you explain me this formula? First "IF" is ok where we are just checking the immediate parent of that child. Why there 2nd "IF" written? Jul 23 '20 at 9:01
  • As the text below the expression explains, you need to check if you have a parent and if you do then you need to check you have a grandparent. It is that simple.
    – Phil W
    Jul 23 '20 at 13:50
  • Yeah I missed that, Got it. Thanks! Jul 24 '20 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.