function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter Kay 6Peter Kay 6 

access parent object fields in child formula

I've spend days searching and made countless attempts and still cannot get this to work. please help.

I simply want to access parent object fields, in this case the parent account record, in a formula in a custom object that has Account as its parent.   From what I read, I should be able to simply state account.name in a formula but I get " Error: Field account does not exist. Check spelling."

I then attempted to duplicate what's in the Salesforce docs https://developer.salesforce.com/page/An_Introduction_to_Formulas which states, "For example, enter Contact.Account.Name to reference the Account Name for a contact associated with a case in a formula field on the Case object."

So I created a custom field in the Case object, then copy/pasted Contact.Account.Name from above. Error message was " Error: Field Contact does not exist. Check spelling.".  So apparently the salesforce documented expression doesn't work. 

I'm at my wits end, taking 2 days and many hours of attempts, getting nowhere. 

It seems something is not right as the field dropdown only shows this in the formula editor in both the Case field test and my own custom object

User-added image


Please help.  If I want to access the account name (or any other account field) in my custom object text field formula.  The object is a child of the Account record. 

Thank you!
BalajiRanganathanBalajiRanganathan
the salesforce exmples are for the standard objects. it will work only if the object for which you are creating formula has the relationship defined. for example, account.name will work on contact object as contact defines account has its parent.

In your custom object, go to the relationship field and check its api name. it would be something like Account__c. then you can access the account field in the forumula using 
relationship name Account__r. so for account name, the expression would be Account__r.name

Also if you have relationship defined, while creating formula, you can click on
Advanced Formula -> insert field -> <your Object> -> <Account> -> account field, then insert to insert the expression in to your formula.
 
Peter Kay 6Peter Kay 6
Thank you for responding. I'm trying to get to a minimal known working situation. Perhaps there are differences in that I'm using Person Accounts.  Here is the error message when, in the Contact record, I attempt to use your example:

User-added image

Notice how the field types don't show account and notice the error message when I use "account.name" in the formula field for a CONTACT record.

My specific instance still has problems. First, I confirmed the relation:

User-added image

Within the Member__c field, the name of the relation is Member__r:
User-added image

So therefore in the formula, the way for me to access, say PersonAssistantPhone according to your direction would be Member__r.PersonAssistantPhone, correct? 

That generates an errror:
User-added image

Finally, you will notice that that the dropdown on field type does not show any non-system objects, for example in this case it should show the Account record which is in a parent relation.

User-added image

Please advise.
Lam CorporationLam Corporation
Hi Peter,

From the last screenshot above you have posted. It looks as if you are trying to edit the "Default Value" of a custom field using a formula. Rather than actually creating a new field of type "formula". I believe this to be the case because you have:
1. "Always require a value in this field in order to save a record" displaying
2. No object fields to choose from
3. "Use formula syntax: e.g., Text in double quotes: "hello", Number: 25, Percent as decimal: 0.10, Date expression: Today() + 7" gives it away. You can only use non object based formulas in this space.
EG of how to use "Default Value":
https://help.salesforce.com/HTViewHelpDoc?id=fields_useful_default_field_values.htm&language=en_US

To look up the parent object use a formula or you may want to consider a workflow rule if required and based of a condition.

Hope that helps.

If it does please mark this as the favourable answer.

Have a good weekend.

LamCorp