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:

  1. 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"
  2. 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
  3. Ensure to add the custom formula field to the Contact page layouts for ease of replicating issue.

  4. Create a Contact with no value in the Account field

  5. 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) ),

Screenshot of Example:


  • 1
    It may be expected, as @sfdcfox says in his answer, based on experience and use, but I would consider that a bug. | Curiosity: Does the same thing occur if you change the static "Test Value From Account" value in the Account formula field to a dynamic/derived value?
    – Moonpie
    May 26 at 15:35
  • 1
    @Moonpie - Yes, it still occurs. This behavior was originally observed with a value from a complex formula field still displaying a value, such as a business channel, even when the lookup field was null.
    – Coogle
    May 26 at 15:38
  • 1
    Thanks. That is helpful, albeit disturbing, information.
    – Moonpie
    May 26 at 15:44

I believe that this is expected. The reason why is that Salesforce presumes the default value for a field when no object is present. That can make all the difference when you do something like adding a custom currency field with a default, non-zero value, and then try to do math with it in another formula in a child object. I'm not sure why Salesforce does this, but I do know it that it does do this.

You should definitely check if a lookup field is not null before using a value from the parent field, especially when that value is a formula or a field that has default values. I'm not even sure that this is documented anywhere, but I have personally observed this in other projects, so I'm not even bothering to build a version in my org to "prove" this, because I feel like that's actually the behavior I've observed before.

  • Thank you for the feedback @sfdcfox! So you think it is on purpose? Even though if the field on the related object is a picklist field, we don't see a default value display? It likely has to do with using the TEXT() function on the primary object, but still, that wouldn't be consistent.
    – Coogle
    May 26 at 15:31
  • @Coogie7 If you had a default value on the picklist, it should show the default value when no other value is present. However, using TEXT probably causes it to fall back in line with your expectations; I would consider that to be the actual bug, if anything. Salesforce tends to return the default value for a field when the reference is null. Again, I don't know why it does, but it does, at least from the times I've been caught off-guard by such behavior.
    – sfdcfox
    May 26 at 15:45

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.