Use the same account next time to pick up where you left off.
|Production Salesforce account||Developer Edition or Admin Playground|
|Do I need to be a Salesforce customer?||Yes||No (It's free!)|
|Can I use it to create my Trailhead profile and store my badges?||Yes||Yes|
|Can I use it to complete Trailhead challenges?||No (except for multiple choices quizzes)||Yes|
|Can I keep my Trailhead badges if I leave my company?||No||Yes (use a personal email address)|
Salesforce has two different user interfaces: Lightning Experience and Salesforce Classic. It’s easy to switch between the two. You can learn about switching between interfaces, enabling Lightning Experience, and more in the Lightning Experience Basics module here on Trailhead.
This module is designed for Salesforce Classic.
You’ve got a lot of data in your organization. Your users need to access and understand this data at-a-glance without doing a bunch of calculations in their heads. Enter formula fields, the powerful tool that gives you control of how your data is displayed.
Let’s say you wanted to take two numeric fields on a record and divide them to create a percentage. Or perhaps you want to turn a field into a clickable hyperlink for easy access to important information from a record’s page layout. Maybe you want to take two dates and calculate the number of days between them. All these things and more are possible using formula fields.
Let’s look at a specific example. What if you wanted to calculate how many days are left until an opportunity’s close date. You can create a simple formula field that automatically calculates that value. By adding the value to the Opportunity page layout, your users can quickly access this key information. You can also add this field to reports and list views for instant access.
When you’re first learning formulas, it’s best to start with simple calculations and build up to more complex scenarios. But, as you’ll see, even simple formulas provide valuable information.
In this unit, we’ll take you through the basics of using the formula editor and introduce you to formula syntax through several basic examples. We’ll also touch on troubleshooting problems with your formula fields. Now let’s have some fun!
Before we dive into writing formulas, let’s locate the formula editor and get to know its features. If you prefer a video introduction, take a look at the video below. Otherwise, keep scrolling.
We don’t need to continue creating this Account formula field, so click Cancel. Now that you know your way around, let’s put the editor to use with some simple examples.
Record detail pages contain a ton of information, but sometimes it’s not enough. Sometimes you need more! For your first formula, let’s do something simple. Let’s take a single field from an Account and show it on a Contact using what’s called a cross-object formula. Let’s take a look.
Congratulations, you’ve written your first formula!
Let’s see this formula in action. The next page lets you set field-level security. For now, click Next so we can add our formula field to the page layout. If you haven’t learned about page layouts yet, check out the UI Customization module. For the time being, make sure that all the checkboxes are selected. Click Next and then click Save.
Now it’s time to see what you’ve done. Open the detail page for the Contact object you just created and find your new Account Number formula field. Cool!
You can also use formula fields in reports to increase the visibility of important information. Say, for example, you wanted a report column that displays the number of days until an opportunity is closed. First, create an Opportunity to test our formula.
We need to find the difference between the opportunity close date and today’s date. Let’s start by inserting the Close Date field in the editor. Since we’re finding a difference, use subtraction. Select - Subtract from the Insert Operator menu.
But how do we tell our formula that we need today’s date? Luckily, there’s a function called TODAY() that updates to match the current date. Find it in the Functions menu on the right side of the editor and click Insert Selected Function.
After you click through the save screens, it’s time to put your new formula field in a report. From the Reports tab, click New Report.... Then select Opportunities and click Create. Your opportunity appears in the Preview panel. Search for Days to Close in the Fields menu on the left side of the page. This field is the formula field you just created. Drag it to the last column in your report. The column populates automatically with the calculated value.
We won’t return to this report, so you can either save it or move directly to the next example.
Organizations often want to count the number of unique objects in a report with hundreds of records. Say, for example, you have a hundred opportunities listed in a report, but only a handful of users own all these opportunities. How do you find the number of distinct users? This task sounds difficult, but it’s one of the easiest formulas you can write. It’s called the Power of One.
To write this formula, create a custom formula field on the User object. Name it Unique Users, give it a Number return type, and select 0 from the Decimal Places drop-down list. Click Next to open the formula editor. For this formula, you don’t need to insert any fields, operators, or functions. Instead, enter the number 1.
You’ll also see this error if you forget a comma between two function parameters. This error is confusing because the actual problem doesn’t match up with the syntax checker. If you’re certain your parentheses are correct, double check that the commas in your function are correct as well.
Another reason you see this error is if you forget to put quotation marks around a text literal or a hyperlink.
The formulas documentation contains numerous examples for many different use cases. While you’re browsing these examples, keep in mind that many of them contain advanced concepts that weren’t covered in this unit. Make sure you’re comfortable with the information presented here before tackling these formulas.
Here are some tips: