Loading

Formula which references a formula on a blank 'relationship' field returns a value instead of null

Veröffentlichungsdatum: Jun 1, 2026
Beschreibung

This article explains why a cross-object formula field returns a partial value instead of null when the lookup relationship field connecting the two objects is blank in Salesforce.

Behavior Description

A cross-object formula on one object that references a formula field on a related object may still return a non-null value even when the relationship (lookup) field connecting the two objects is empty.

Example Scenario

Consider two objects — Object A and Object B:

  • Object A has a text field (text_field__c) and a formula field (formula_field__c). The formula field concatenates text_field__c with a text string, such as: text_field__c & "@test.com"
  • Object B has a lookup relationship to Object A, and a formula field that references Object A's formula field: Object_A__r.formula_field__c

Result: On an Object B record where the lookup to Object A is blank, the formula on Object B displays "@test.com" instead of null.
Salesforce-specific example: On an Opportunity record with a lookup to Account, if a formula on the Opportunity references Account.Email_Domain__c (a formula field on Account that appends "@company.com" to a domain text field), the Opportunity formula returns "@company.com" even when the Account lookup field is empty.

Lösung

Root Cause Explanation

This is expected behavior in Salesforce. When a formula field references another formula field, Salesforce pulls in the underlying syntax of the referenced formula — not just its current value. This means the formula on Object B effectively evaluates the full expression Object_A__r.text_field__c & "@test.com" directly.
When the lookup to Object A is blank, Salesforce cannot retrieve Object_A__r.text_field__c, so that portion of the formula evaluates to null. The remaining formula logic evaluates as null & "@test.com", which outputs "@test.com".

Recommended Fix

To prevent a cross-object formula from returning partial values when the lookup field is blank, wrap the formula with an IF function that checks whether the lookup relationship is null before evaluating the formula expression.
Updated formula example for Object B:
Use an IF statement to first check if the Object A lookup is populated. If the lookup is blank (null), return null. If the lookup is populated, evaluate the cross-object formula as intended. For example: IF(ISNULL(Object_A__r.Id), NULL, Object_A__r.formula_field__c).
This prevents the formula from returning partial text values (such as "@test.com") when the lookup relationship field is empty.

Nummer des Knowledge-Artikels

000381947

 
Laden
Salesforce Help | Article