0

I found this question Best Practice: Formula field Vs new (duplicate) field but it's a bit old and it didn't get much traction anyway.

I have a field Minion__c in the parent record and I need a field Parent_Minion__c in the child record with the same value as the parent. What is the best practice in this case?

  • Create a formula field in the child object and reference the parent parent.Minion__c
  • Use automation (Flow, Trigger) to copy the value down from the parent to the child

Would the recommendation change if Minion__c in the parent is a lookup field?

4
  • 1
    Hi. It probably didn't get traction because "best practice" is likely to be somewhat opinionated but also very much on a case-by-case basis. There are occasions where a cross-object formula makes 100% sense, and others where a "denormalized" field "duplication" makes sense too.
    – Phil W
    Jul 19, 2022 at 15:46
  • Can you please edit to add the type of the Minion__c field? See comments on the (downvoted) answer as to why this is important. (You sort of hint at this with the final question...)
    – Phil W
    Jul 19, 2022 at 15:54
  • It is impossible to clearly state what best practice is when you do not clarify how you would consume the value.
    – Adrian Larson
    Jul 19, 2022 at 19:01
  • I didn't specify a field type on purpose because I want opinions on the best practice for relationship fields vs non-relationship fields. Jul 19, 2022 at 19:16

3 Answers 3

0

While not "best practice", versions of this formula have been floating around for a while and can work "pretty good" for some situations.

Modify for your use case (e.g. replace "Subject" with your custom field name). Keep in mind the caveats and limitations from other comments as it is a high resource solution.

This is a formula from the Case object and creates a link to the root parent case from any child record within five levels. Adjust/reduce levels as needed.

/* First hyperlink allows sort by subject instead of ID in reports/lists */

HYPERLINK("/?sort=" +
BLANKVALUE(Parent.Parent.Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Subject,
BLANKVALUE(Parent.Subject,
Subject))))), "", '_self') +
HYPERLINK('/lightning/r/' +
BLANKVALUE(Parent.Parent.Parent.Parent.Parent.Id,
BLANKVALUE(Parent.Parent.Parent.Parent.Id,
BLANKVALUE(Parent.Parent.Parent.Id,
BLANKVALUE(Parent.Parent.Id,
BLANKVALUE(Parent.Id,
Id))))) & "/view",
BLANKVALUE(Parent.Parent.Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Parent.Subject,
BLANKVALUE(Parent.Parent.Subject,
BLANKVALUE(Parent.Subject,
Subject))))),"_self")
-1

If Minion__c is a lookup field on the parent, you could create a formula field on the child:

HYPERLINK('/' & Parent__r.Minion__c, 
          Parent__r.Minion__r.Name )

that will allow someone on the child's record detail page to directly access to Minion lookup record

2
  • The question is about best practices, not about how to do it. Jul 20, 2022 at 12:57
  • 1
    For lookup fields, the above is an acceptable practice as it avoids writing sync’ing code/automation. It assumes you manage changes to the lookup field strictly from the parent object.
    – cropredy
    Jul 20, 2022 at 13:13
-2

You can use formula field instead of flow/trigger.

Your formula field should be like below.

Parent__r.Minion__c

Whenever Minion__c field value changes at parent level same value will be update at child level.

5
  • 1
    Note that such a cross-object formula field comes at a cost. First, you can only have up to 15 unique relationships traversed in all cross-object formula fields in a given object, including those added by packages installed from the app exchange or elsewhere. Second, the value is computed on demand and doesn't allow any automation to be initiated simply because its value changes. Third, if the user has permission to read the formula field they can see the value even if they don't have read permission on the related object field. That said, such formula fields are excellent for many uses
    – Phil W
    Jul 19, 2022 at 15:42
  • 1
    "Whenever Minion__c field value changes at parent level same value will be update at child level." isn't strictly true since formula field values are only ever computed, never stored. These are computed when required (i.e. when queried or formulas are recalculated on an SObject via Apex).
    – Phil W
    Jul 19, 2022 at 15:44
  • 1
    Oh, and another issue with (cross-object) formula fields; these cannot result in an Id (Lookup field), so if your parent.Minion__c is a Lookup field, you can't generate a Minion__c Lookup on the child using a formula.
    – Phil W
    Jul 19, 2022 at 15:50
  • 1
    @Ankaiah Bandi, Downvoting the answer because this is clearly a best practices question, not a question about how to implement. Jul 19, 2022 at 15:52
  • @Phil W, all good points, thank you. Jul 19, 2022 at 15:53

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.