### What is a formula field?

Data within a formula field is automatically updated by Salesforce based on the formula’s logic.

For instance, the sales team speaks with clients in terms of a monthly and yearly cost. However, the monthly cost is simply the yearly cost divided by 12. Instead of making the reps do the math, we can do it for them. Enter a yearly cost of $120.00, the monthly cost a formula will display $10.00. Change the yearly cost to $240.00, monthly cost is automatically updated to $20.00.

### What is a cross-object formula?

A Cross Object Formula is one that references data in a related record. For instance, I could create a formula field on opportunity to display the account’s phone number.

When the account’s phone number gets updated, the field on opportunity automatically reflects the change.

### What’s important to know about formulas?

- Formula fields are read-only (the same is true for roll-up summary fields) for all users.
- For this reason, formula fields will not be displayed when editing records. The value of the formula is only calculated after the record is saved. This applies to cross-object formulas as well. For instance, you can easily display the account’s phone number on the opportunity, but you cannot edit the phone number without returning to edit the account record.

### Limitations of Formula Fields

There are considerations to be aware of when building formula fields. Notably:

- Formula fields cannot reference several field types, including (but not limited to): Text Area (Long), Text Area (Rich), Picklist (Multi-Select).
- Some formula fields cannot be referenced by roll-up summary fields.
- There are several restrictions on formula size (character, save, compile). You can hit these on long/complex formulas with many arguments.

### How do you create a formula field?

Simply create a new field, and select field type “Formula”. Then enter the return type and syntax.

### Simple & Advanced Formula Editors

When editing formula syntax, there are two types of editors:

The simple editor does not provide access to cross-object formulas or functions:

I recommend using the Advanced Formula editor, which exposes cross-object variables and functions:

### Sample Formulas

Examples of Advanced Formulas

[Must / Long / Salesforce.com]

100 Sample Formulas to Get you Started

[Should / Long / Salesforce.com]

The first link in the Sample Formulas section at the very end isn’t a valid link:

Examples of Advanced Formulas

[Must / Long / Salesforce.com]

Any other recommendations on where I can see some more examples of advanced formulas?

Thank you!

Looks like this link is working- might have been out temporarily?

IF(ISPICKVAL(StageName, “Closed Won”),

ROUND(Amount *0.02, 2), 0)

What the “2” stands for ?

got it thanks !

Hi,

How can i create a create a formula field in the opportunities object which takes the phone from the lead object as a cross object reference.

Thanks!!

Look at https://certifiedondemand.com/formulas-scenario-1/ for an example

What’s interesting is when I create a Account Phone field on the Opportunity object, it sees Phone as a text data type. So I select create new formula field in the Opportunity object. I give it a field label. The Formula return type options are just :

Checkbox

Currency

Data

Date/Time

Number

Percent

Text

there is no option for Phone in the formula return type. I tried selecting number and once I enter the formula to get the account phone, it gave me an error that there was a data type mismatch. So I changed it to text and it worked. So it seems like when it comes to formula, phone is treated as text.

Yep that’s the right approach!

The sample formula pages are GOLD!!!

Thanks,

Hi John ,

With regards to the Cross object Formula , do we have to do add it to every Object that we have ? I will give an example to help explain myself . What if we have the phone number field added to other Objects other than ” Account ” , and only Account had this link with Opportunity so that if the Phone number changes in Account it will change in the Opportunity Field . Is there any way that the Phone number will change in all fields that are concerned with Phone number

Thanks in advance ,

Omar ,

You would have to create a field on each object that you want to capture/display the information, yes.

Hello John

Is it possible to relate with a cross formula option in the same Relation ?

For example it i create custom adress field i just want to relate to the standard billingadress field

best regards john s.

Not sure I completely understand the question – you can reference address fields in formulas. If you wanted to update a standard address field you would need to use a workflow rule, which could reference a formula in the workflow.

I know I’ve seen the answer to this somewhere, but now I can’t find it: What is the “!” in some formulas; where does it come from or how is it used? Thanks!

The ! variables are those used in email templates (the syntax in a formula field will look different) – not sure why the two are different…

Thanks, John!

I also have same question, when is “!” used in formula

! In formula fields is used for global variables such as role and profile

Is there a limit to a certain number of characters in the length of a formula? Is it 4000?

There are a few different limitations – https://help.salesforce.com/apex/HTViewHelpDoc?id=formula_field_limits.htm&language=en_US

From my experience the compile limit is the one you are most likely to hit, but it could be the character or save size limit as well.

Tiny typo in the 2nd sentence in the 2nd paragraph: “cost is a simply the”.

Thanks, updated!

Hi John – The links within “Examples of Advanced Formulas” bring you to a Saleforce page discussing disabling SSL 3.0 encryption. I clicked on several of the links and received the same result.

This appears to work for me- could have been a temporary problem?

Hi John – you have indicated those two Sample Formula documents as being “Must” and “Should” – do we need to know all the formulae from all the examples?

You should be well versed in the capabilities of formulas and have a solid understanding of the syntax – you don’t know necessarily need to memorize everything but you should definitely have a high degree of familiarity.