Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Salesforce Parent-Child Formula: How-To Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You cannot build a true parent-child relationship with a formula in Salesforce. Formulas can only read values that already exist on the same record or on records reached through a lookup or master-detail relationship; they cannot create, link, or traverse child records. What you can do is surface parent data on a child record with a cross-object formula, or roll child data up to the parent with a roll-up summary field (master-detail only) or a Flow. This guide walks through the working options and the mistakes that make people think a formula failed.

What You'll Need

  • Permission to edit the object and create custom fields (usually System Administrator or a custom profile with Modify All Data or object-level field permissions).
  • An existing lookup or master-detail relationship between the two objects. A formula cannot invent one.
  • For roll-ups: a master-detail relationship. Standard lookups cannot use roll-up summary fields.
  • For lookup-based roll-ups: Salesforce Flow (record-triggered) or Apex, plus a test record to confirm behaviour.
  • A sandbox or a small test data set before you touch production.

Step-by-Step

  1. Decide which direction you need. Parent-to-child means showing a parent field on the child record (cross-object formula). Child-to-parent means aggregating many child records on the parent (roll-up summary or Flow). These are different tools; picking the wrong one is the most common reason people get stuck.
  2. Confirm the relationship type. Open Setup, go to Object Manager, select the child object, and open Fields & Relationships. Check whether the field to the parent is a Lookup or Master-Detail. Labels and menu names vary slightly by Salesforce release and edition, but Object Manager is the constant entry point.
  3. For parent-to-child, create a formula field on the child. In Object Manager, open the child object, choose Fields & Relationships, then New. Select Formula, give it a label and API name, and choose the return type (Text, Number, Date, Checkbox).
  4. Insert the cross-object reference. In the formula editor, use Insert Field and drill into the lookup/master-detail relationship name, then pick the parent field. The result looks like Parent__r.Name or Account.Owner.Name. Note the __r suffix for custom relationships; standard relationships use the plain name.
  5. Guard against blanks. If the lookup can be empty, wrap text references in BLANKVALUE() or use IF(ISBLANK(Parent__c), "No parent", Parent__r.Name). Without this, the formula returns blank and looks broken.
  6. Save, then add the field to the page layout. A formula field that is not on the layout will not appear on the record page. Use Lightning App Builder or the page layout editor, depending on how the page is built.
  7. For child-to-parent totals on master-detail, create a roll-up summary. On the parent object, create a new field and choose Roll-Up Summary. Pick the child object, choose COUNT, SUM, MIN, or MAX, and optionally add filter criteria. This recalculates automatically and needs no formula.
  8. For child-to-parent totals on a lookup, use Flow. Build a record-triggered Flow on the child object (created, updated, or deleted as needed) that updates a number field on the parent. Add a Get Records step to total the children, then an Update Records step on the parent. Test with create, edit, and delete actions, because deletes are the case most people forget.
  9. Test with real records. Create a parent with two children, change a child value, delete a child, and clear a lookup. Confirm the formula or roll-up reflects each change. Formula fields recalculate on save; roll-ups recalculate when the child changes.

Common Mistakes

  • Expecting a formula to link records. Formulas display data; they do not create relationships. Use a lookup or master-detail field for that.
  • Trying a roll-up summary on a lookup. Salesforce only offers roll-up summaries for master-detail relationships. Use Flow or Apex instead.
  • Forgetting the __r suffix. Custom relationship references need __r; using __c produces a syntax error.
  • Ignoring blank lookups. A cross-object formula returns blank when the parent is missing, which looks like a failure but is expected behaviour.
  • Leaving the field off the layout. The formula works but nobody sees it.
  • Skipping delete testing on Flow roll-ups. A Flow that only fires on create and update will leave stale totals after a child is deleted.
  • Changing a lookup to master-detail without a plan. This conversion has data and sharing implications; review Salesforce help before doing it.

Tips

  • Name formula fields clearly, for example Parent_Account_Name_Formula, so admins know it is derived and not editable.
  • Use ISBLANK() and BLANKVALUE() together for text fields that may be empty.
  • Keep cross-object formulas shallow. Deep chains are harder to maintain and can hit compile limits.
  • Document any Flow-based roll-up in the field description so the next admin knows why the number is not a native roll-up.
  • Build in a sandbox first, then deploy with a change set or your normal release process.

Troubleshooting

If the formula field shows blank, check that the lookup is populated and that the parent record is visible to the running user; cross-object formulas respect sharing and field-level security. If you get a syntax error, confirm the relationship API name and the __r suffix. If a roll-up summary option is missing, the relationship is a lookup, not master-detail. If a Flow-based total is wrong, check whether the Flow fires on delete and whether the Get Records step filters the right child records. If the field is missing from the page, add it to the layout or Lightning page. If nothing recalculates after a data change, confirm the change was saved, not just typed into the form.

Frequently Asked Questions

Can a formula create a parent-child relationship?

No. Relationships are created with lookup or master-detail fields. Formulas only read values across an existing relationship.

Can I roll up child records through a lookup?

Not with a native roll-up summary. Use a record-triggered Flow or Apex to total the children onto the parent.

Why does my cross-object formula return blank?

The lookup is probably empty, or the running user cannot see the parent record or field. Check both.

Do formula fields update automatically?

Yes, they recalculate when the record is saved or when a referenced value changes, so no manual refresh is needed.

What is the difference between __c and __r?

__c is a custom field; __r is a custom relationship reference used to reach fields on the related record.

Can I use a formula on the parent to count children?

No. A parent formula cannot see its children. Use a roll-up summary on master-detail or a Flow on lookup.