I believe I've identified a bug in Salesforce related to formula fields. Can some of my fellow developers, and admins too, confirm if I am observing unexpected behavior? I do have a workaround.
The issue is reproducible in the following manner in any developer sandbox using the Account and Contact standard objects:
Create a custom formula field on the Account object with the following attributes:
Field Label = Test Formula Test Feld - Account Field Name = Test_Formula_Text_Field Field API Name = Test_Formula_Text_Field__c Type = Text Formula = "Test Value From Account"
Create a custom formula field on the Contact object with the following attributes:
Field Label = Test Related Formula Text Field - Acct Field Name = Test_Related_Formula_Text_Field_Acct Type = Text Formula = Account.Test_Formula_Text_Field__c
Ensure to add the custom formula field to the Contact page layouts for ease of replicating issue.
Create a Contact with no value in the Account field
Navigate to the new Contact and look at the “Test Related Formula Text Field - Acct” field
Expected Behavior: No value is display in the “Test Related Formula Text Field - Acct” field since there is no value in the Account field on the Contact record.
Actual Behavior: The value “Test Value From Account” is displayed.
Additional Notes: The unexpected behavior occurs when using other field types like Time. The expected behavior occurs when the field on Account (or the related object of the lookup field) is a picklist (even with a default value), and the resulting formula on Contact encases the picklist field in the TEXT formula function.
Workaround: Until this issue is resolved, the workaround is to add logic to display a null/blank value when the lookup field is null. Example formula workaround for our test scenario:
IF( NOT(ISBLANK(AccountId) ),
Account.Test_Formula_Text_Field__c,
NULL
)
Screenshot of Example: