Salesforce Data
Salesforce Data
Formula Field
Cross Object Formulas
Field Dependencies
Roll up Summary Fields
Validation Rules
Formula Field
There is a lot of data in an organization. The users need to access and understand this data at a
glance without doing a bunch of calculations in their heads.
Formula fields, the powerful tool that gives us control of how our data gets displayed.
Examples:
Take two numeric fields on a record and divide them to create a percentage.
Turn a field into a clickable hyperlink for easy access to important information from a
record’s page layout.
Take two dates and calculate the number of days between them.
All these things and more are possible using formula fields.
First create a Contact. If you’ve never created a Contact before, click the App Launcher and
select Contacts. Then go to the Contacts tab and click New. Enter any value for Last Name. For
Account Name, enter an existing account such as United Oil & Gas Corp. Click Save. Next we
create a formula to display the account number on the Contact page.
Assignment:-
In the Visits object, when a hospital is associated, the hospital phone and email should also be
populated in two other fields
11. Click Next to accept the field-level security settings, then click Save.
Now it's time to put your new formula field in a report.
1.From , open the Report tab and click New Report.
2.Enter Opportunities in the Search Report Types... field. Select Opportunities and
click Continue. Your opportunity appears in the Report Preview panel.
3.Make sure Update Preview Automatically is enabled.
4.In the Add column... field on the left side of the page, enter Days to Close . This
field is the formula field you just created. A column with the field containing the
calculated value is automatically added to the report.
You won't need the report again for this unit. You can discard it and move on to the
next example.
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
dropdown 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.
Yes, that’s really it! Save your formula as usual, and then click the Reports tab to see it in action.
Create an Opportunities report and make sure that Update Preview Automatically is enabled. In
the Add column... field on the left side of the page, enter Unique Users to add a column with the
new field to the report. If you are unable to see the new field, refresh the Reports tab. You should
see something similar to the following (your report may appear different, depending on what
columns you have displayed).
Here, we have five opportunities between two distinct users. Where does our formula come in?
On the Unique Users column, click the dropdown menu and select Summarize and then Sum.
The number of distinct users appears at the bottom of the column. As you can see, even simple
formulas provide powerful insights into your organization.
Assignment:-
Create a Formula Field
Create a formula field that calculates the number of days remaining before a contract expires.
Object: Contract
Formula: Calculate the number of days between the contract end date and today
Create a formula field on 'Invoices' object so as to calculate an offer amount. The company
provides 10% offer if total amount is > 10000 else 5%
Write a formula to calculate a person's age based on the birthdate (Use 'Contacts' object)
The formula field should display the value 'Yes' if the contact's birthdate falls in the current
month
If the stage of the opportunity is 'Closed Won', then calculate commission which is 2% of
the amount
Roll Up Summary
Roll Up Summary
While formula fields calculate values using fields within a single record, roll-up summary fields
calculate values from a set of related records, such as those in a related list. You can create roll-up
summary fields that automatically display a value on a master record based on the values of
records in a detail record. These detail records must be directly related to the master through a
master-detail relationship.
You can perform different types of calculations with roll-up summary fields. You can count the
number of detail records related to a master record, or calculate the sum, minimum value, or
maximum value of a field in the detail records. For example, you might want:
A custom account field that calculates the total of all related pending opportunities.
A custom order field that sums the unit prices of products that contain a description you
specify.
Master-Detail Relationships
Master-detail relationships closely link objects together so that the master record controls specific
behaviors of the detail and sub detail record.
You define a roll-up summary field on the object that is on the master side of a master-detail
relationship. For example, you can create a roll-up summary field on the Account object,
summarizing related opportunities:
There are a few different types of summaries you can use.
Type Description
COUNT Totals the number of related records.
Totals the values in the field you select in the Field to Aggregate option. Only number,
SUM
currency, and percent fields are available.
Displays the lowest value of the field you select in the Field to Aggregate option for all
MIN directly related records. Only number, currency, percent, date, and date/time fields are
available.
Displays the highest value of the field you select in the Field to Aggregate option for all
MAX directly related records. Only number, currency, percent, date, and date/time fields are
available.
The MIN of all Created Date fields on the Opportunities object displays the earliest date an
opportunity was created related to an account.
Total Price is summarized on the Opportunity Product object to find the grand total of all
products related to an opportunity.
Minimum List Price of An Opportunity
A roll-up field was created on the Opportunities object.
List Price is summarized on the Opportunity Product object to find the product with the lowest
price related to an opportunity.
Imp Points:-
Congratulations on creating your first roll-up summary field! Keep in mind that the types of
fields you can calculate in a roll-up summary field depend on the type of calculation. For
example:
Number, currency, and percent fields are available when you select SUM as the roll-up
type.
Number, currency, percent, date, and date/time fields are available when you select MIN
or MAX as the roll-up type.
Assignment