In Chapter 4, we looked at an overview of Lightning Experience and studied the dynamic record page. Last, we discussed use cases for custom buttons, links, and actions using real-life examples.
This chapter is comprised of two parts. The first part is divided into two sections; part two is divided into three sections.
In part one, the first section consists of an overview of record types; the second section takes a look at lookup filters and dependent lookups.
In part two, the first section consists of an overview of formula fields, the second section discusses a use case of a roll-up summary field, and the last section examines the best way to write enterprise-level validation rules using custom permissions.
Record Types: A Better Way to Handle Varied Business Processes
Record types play a key role in Salesforce implementation. Without having a good understanding of them, developers or architects may end up devising an incorrect solution or writing code, which may turn out to be a suboptimal solution.
Representation the Data Marketing Director Wants to Capture
Manufacturing | Other |
---|---|
First Name Last NameE-mailEventIndustry (Manufacturing, Shipping, Consulting, and Other) PhoneAnnual Income*Date of Birth* Shift Hours* | First Name Last NameE-mailEventIndustry (Manufacturing, Shipping, Consulting, and Other) Phone |
Now there are various ways to meet this requirement. For example, we can write validation rules that state that whenever the value in the Industry field is Manufacturing, make the three other fields required. This requires users to populate the fields before they can save the record.
Even if the validation rule works, it will create a negative user experience because the required fields, as a result of the value Manufacturing in the Industry field, would not have red asterisk attached to it.
- 1.
Right off the bat, it creates a negative user experience because the required fields (only when the value in the Industry field is Manufacturing) would not display a red asterisk next to it!
- 2.
Second, what happens if users select a value other than Manufacturing in the Industry field? In such a scenario, they would be able to skip entering the data in the aforementioned required fields because the validation rule would not trigger if the value in the Industry field is anything other than Manufacturing. This situation creates a big dent in achieving, and maintaining, data integrity—to say the least!
To avoid a negative user experience or avoid compromising data integrity, developers and architects have to write a complex validation rule.
- 3.
The validation rule route displays unnecessary fields on a page layout when a value other than Manufacturing is in the Industry field. In such a scenario, fields like Annual Income, Date of Birth, or Shift Hours would gobble up page layout real estate without adding any value—not to mention delivering a suboptimal user experience.
- 4.
Last but not least, with the validation rules route, confusion, a negative user experience, and clutter in the page layout skyrockets if developers or architects are tasked with adding a few custom buttons or links to the page layout specific to the manufacturing industry!
Still not convinced the validation rules route may be a suboptimal solution? Well then, let us take a look at another example.
Assume the marketing director is happy with the validation rules solution you provided, and that it works as of today. However, the director now walks into your office and tasks you with a new requirement: she wants the value in the Industry field to be Shipping. When the value in the Industry field is Shipping, you need to create more than 40 fields. The marketing director also wants to gather additional data, such as participants’ current job duties and bonuses, when the value is Shipping. To avoid confusion, a negative user experience, and clutter in the page layout, the director does not want the 40 fields to be displayed if the value in the Industry field is not Shipping.
In light of this situation, do you still think the validation rules route is an optimal solution? I don’t think so either. To conclude, because page layout doesn’t allow users to show/hide fields based on the value of another field, the validation rules route falls short. Developing a solution for the various scenarios just described requires developers and architects to use record types as an option.
What Are Record Types?
Record types allow you to group similar fields and display them to users as necessary. They do so by enabling you to segment a particular object’s fields/sections for specific uses.
Record types to rescue! Record types help improve the sales rep experience by displaying appropriate sections/fields on a page layout based on an Opportunity stage .
- 1.
To show different page layouts based on conditions. For example, if an Opportunity stage is Closed Won or Closed Lost, then, display the Read Only page layout.
- 2.To show/hide picklist values. For example, if an Opportunity type is Existing business, then remove the following values from the Lead Source field:
Partner
Employee Referral
Other
As a developer, you can create three different page layouts—Discovery, Billing, and Shipping—then display different fields on the page layout based on the value in the Opportunity stage field.
Page Layouts and Their Dependency on the Opportunity Stage
Page Layout | Stage |
---|---|
Discovery | Prospecting |
Billing | Proposal/Price Quote |
Shipping | Closed Won |
Let’s get back to our business scenario with Robin Guzman. He’s received a request from his manager to configure the Registrant custom object based on Table 5-1.
- 1.
Robin navigates to Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Create ➤ Custom Object and creates a new custom object, Registrant, and all the fields mentioned in Table 5-1.
- 2.
Next, he creates two page layouts by navigating to Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Registrant ➤ Page Layouts.
- 3.
Last, Robin creates two record types—Manufacturing and Others—and then assigns page layouts as shown in Figure 5-6.
How Record Types Control Lightning Record Pages
I have seen many questions from people, as part of the Trailblazer Community, wondering how record types and page layouts are connected in Lightning record pages. Here is my answer: a record type can control both page layout and Lightning record pages at the same time, because they are separate components.
Figure 5-8 also shows that users in two different profiles can not only have the same page layout, but also they can have different Lightning record pages configured for their profiles—and vice versa!
Basically, in Lightning Experience, you use Classic page layout as a component (Record Detail), which sits on top of the Lightning record page. This means both are separate Lightning components. Therefore, both are configurable at the object level.
After you create a Lightning record page, click the Activation button to assign the Lightning record page based on record types and profiles.
Lookup Filter: Limit the Records That Can Be Shown in a Lookup Window
A lookup filter is one of the best tools to enrich data quality by enforcing data consistency. The filters limit fields and values displayed in a lookup dialog and, as a result, enforce access to valid values. The filter can be used when objects are in a lookup, master detail, or hierarchical relationship.
Let’s look at an example. Pamela Kline has been given the requirement to restrict the Account Name field on opportunities by only allowing accounts with type Customer and by filtering out any other types of accounts.
- 1.
She clicks Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Opportunity ➤ Fields & Relationship ➤ Account Name and then clicks the Edit button.
- 2.
Then, she navigates to the Lookup Filter section and clicks Show Filter Settings.
- 3.
Pamela clicks the search icon and chooses Account Name. Then she chooses Type and clicks Insert.
- 4.
For Operator, she chooses equals.
- 5.
For Value/Field, she chooses Value.
- 6.
Then, she clicks the search icon and chooses Customer.
- 7.
Next, she clicks Insert Suggested Criteria.
- 8.At the end, she makes sure the filter type is set to Required and the Active check box is selected, as shown in Figure 5-10.
- 9.
When done, Pamela clicks the Save button.
Going forward, whenever a sales rep creates a new opportunity, Salesforce only shows the account’s whose type is Customer.
Formula Fields: Small Work, Big Impact
Pamela Kline wants to display a few fields from Account, such as Site, Industry, and Annual Revenue, on an Opportunity record so sales reps can see all data in one place.
Pamela wants to know if a customer’s birthday falls in the current calendar month.
Pamela wants to create a clickable phone number field that dials a phone number automatically, using a dialing tool, when clicked.
Carolina Lopez, a sales manager at GoC, wants to share monthly installation with support agents, but not the Loan Amount and Interest Rate fields, which reside in the Loan Details custom object.
The common objective in all the aforementioned scenarios is to perform some kind of automation. There are a few automation tools in Salesforce and each one has unique features. For now, we will use formula fields to solve the business scenarios just presented. In the next chapter, however, we study several automation tools in depth.
When you reference a field from the parent object in a formula’s expression, this type of formula is known as a cross-object formula , as shown in the screenshot in Figure 5-11. Using cross-object formulas, you can reference a field from the parent object (regardless of the whether the relationship is lookup or master detail).
You can create formula fields on standard or custom objects, but not on an external object. As of the Summer 2019 release, it is not possible to refer to fields on external objects in a formula. Any changes in the formula’s expression are reflected automatically in the formula’s field value.
Let’s rejoin Pamela Kline, a system administrator at GoC, who has been given the requirement to display the annual revenue of a customer on the Contact record.
To meet the requirement, Pamela performs the following steps:
- 1.
She clicks Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Contact ➤ Fields & Relationship and clicks the New button.
- 2.
Then she selects Formula as the data type and clicks the Next button.
- 3.
She enters the field label Annual Revenue and chooses Currency as the data type, then clicks the Next button.
- 4.
- 5.
- 6.When done, Pamela sees the formula’s expression (1 in Figure 5-14) in the text area. She can also use the functions (2 in Figure 5-14) provided by Salesforce to write a complex formula. (Functions are convoluted operations that are preimplemented by Salesforce.) After Pamela writes the formula, she clicks the Check Syntax button (3 in Figure 5-14) to confirm everything is in working order before saving. If there is a problem with her formula, the syntax checker will warn her.
- 7.
Pamela the clicks the Next button, which redirects her to the page where she can establish field-level security. She does not make any changes, but leaves all the settings as default settings.
- 8.
She clicks the Next button again, which allows her to add the formula field to her page layout.
- 9.
Once done, she clicks the Save button.
Tip
Check out the help documentation published by Salesforce to learn more about formulas (https://help.salesforce.com/articleView?id=customize_functions.htm&type=5).
Rollup Summary Field
A rollup summary field is a custom field used to calculate values from related records and to display the value on a parent record. You can create rollup summary fields on parent records only if the objects have a master detail relationship.
COUNT: This function is used to count the total number of related records.
SUM: This function is used to sum values in the related record’s field. You select the field from the Field to Aggregate drop-down. Only currency, number, and percent fields are available for selection.
MIN: This function is used to find the minimum value on a field. You select the field from the Field to Aggregate drop-down, across all related records. Only currency, date, date/time, number, and percent fields are available for selection.
MAX: This function is used to find the maximum value on a field. You select the field from the Field to Aggregate drop-down, across all related records. Only the currency, date, date/time, number, and percent fields are available for selection.
Let’s rejoin Pamela. She has been given a new requirement to display Sum of Open Opportunities Amount in the Account record. To meet this requirement, Pamela performs the following steps:
- 1.
She clicks Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Account ➤ Fields & Relationship, then clicks the New button.
- 2.
She then selects Roll-up Summary as the data type and clicks the Next button.
- 3.Pamela enters the field label Total amount (Open opportunities) and clicks the Next button, which opens a window where she enters the following details:
- a.
Summarized Object: She selects the Opportunities object (1 in Figure 5-17).
- b.
Select Roll-Up Type: She selects SUM as the rollup type (2 in Figure 5-17).
- c.
Field to Aggregate: She selects Amount in the Field to Aggregate drop-down (3 in Figure 5-17).
- d.
Filter Criteria: She selects Only records meeting certain criteria should be included in the calculation (3 in Figure 5-17) and then she selects Closed ➤ equals to False (4 in Figure 5-17) as filter criteria. At the end, her screen looks like Figure 5-17.
- a.
- 4.
When done, Pamela clicks the Next button, which redirects her to the page where she can establish field-level security. She doesn’t make any changes, but leaves them as default values.
- 5.
She clicks the Next button, which allows her to add the rollup summary field to her page layout.
- 6.
Last, Pamela clicks the Save button.
Salesforce now populates Total amount (Open opportunities) field values for all opportunities. Remember, rollup summary fields are Read Only fields; no one is allowed to edit their value.
Tip
Check out the help documentation published by Salesforce to discover hidden gems regarding the rollup summary field (https://help.salesforce.com/articleView?id=fields_about_roll_up_summary_fields.htm&type=s).
Validation Rules
A validation rule can contain a formula that evaluates the data in one or more fields and returns a value that is either True or False, where true means no error and false means there is an error. You can display the validation rule error message either at the top of the page (1 in Figure 5-18) or next to the field (2 in Figure 5-18).
- 1.She clicks Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Account ➤ Validation Rules, then clicks the New button. This opens a window where she enters the following details:
- a.
Rule Name: Pamela types Annual_revenue_cannt_be_greater_than_1bn.
- b.
Description: She writes some meaningful text so other developers and administrators can understand easily why this custom field was created.
- c.Error Condition Formula: She uses the following formula:OR(AnnualRevenue < 0,AnnualRevenue > 1000000000)
- d.
Error Message : She enters the following message: Annual revenue cannot exceed 1 billion.
- e.
Error Location: She selects the Annual Revenue field.
- a.
- 2.At the end, her screen looks like Figure 5-19.
- 3.
Last, Pamela clicks the Save button.
Going forward, if users update their annual revenue with an amount greater than US$1,000,000,000, they get an error message and have to fix the error before they can save the record.
Tip
Check out the help documentation published by Salesforce to find examples of validation rules (https://help.salesforce.com/articleView?id=fields_useful_field_validation_formulas.htm&type=5).
Custom Permissions: A Way to Bypass Validation Rules
Carolina Lopez, Regional Sales Manager
Jerry Shannon, VP Sales
Donna Serdula, Senior Vice President
Pamela is also told that, in the future, the list of users may grow!
Pamela wonders whether there is a better way to handle this requirement. She doesn’t want to modify the validation rule every time she is required to add a new user to the bypass validation list.
Custom permissions to rescue! Pamela learned recently that, by using custom permissions, she can grant users access to custom apps. In Salesforce, she can use custom permissions to check which users can access a certain functionality. Using custom permissions, she can bypass validation rules, formula fields, Process Builder, Apex triggers, and so on. Custom permissions let her define access checks that can be assigned to users via profiles or permission sets.
- 1.
She clicks Setup (gear icon) ➤ Setup ➤ PLATFORM TOOLS ➤ Custom Code ➤ Custom Permissions, and clicks the New button.
- 2.She creates a custom permission, as shown in Figure 5-21.
- 3.Now she creates a permission set (“Bypass validation rule”) and assigns the custom permission Bypass Validation Rule to it, as shown in Figure 5-22).
- 4.
Next, Pamela modifies the annual revenue validation rule to add a custom permission check. To do so, she navigates to Setup (gear icon) ➤ Setup ➤ Object Manager ➤ Account ➤ Validation Rules and edits the annual revenue validation rule.
- 5.She modifies the formula as follows:AND(NOT($Permission.Bypass_validation_rule), OR(AnnualRevenue < 0,AnnualRevenue > 1000000000))
- 6.
- 7.
Last, she clicks the Save button.
Pamela assigns the Bypass Validation Rule permission to users Carolina Lopez, Jerry Shannon, and Donna Serdula. And that’s it! Now the validation rule is bypassed for these users. In the future, if Pamela wants to bypass a validation rule for other users, all she has to do is to assign the permission set to those users.
Points to Remember
- 1.The following picklist fields are not available for record types because they are controlled by sales processes, lead processes, support processes, and solution processes respectively:
- a.
Opportunity Stage
- b.
Case Status
- c.
Solution Status
- d.
Lead Status
- a.
- 2.The following campaign member picklist fields are not available for record types:
- a.
Status
- b.
Salutation
- c.
Lead Source
- a.
- 3.
It is not possible to deactivate a record type if it is in use by the Email-to-Case or On-Demand Email-to-Case routing e-mail address.
- 4.
Lookup filters improve user efficiency by controlling the number of available records in a lookup search dialog.
- 5.
In Lightning Experience, a lookup filter doesn’t work if a field referenced in the filtered lookup isn't added to the page layout.
- 6.
It is not possible to refer to cross-object formulas in rollup summary fields.
- 7.
Salesforce allows a maximum of ten unique relationships per object in cross-object formulas.
- 8.
Formula fields can comprise up to 3900 characters, including spaces, return characters, and comments. If your formula needs more characters, create separate formula fields and reference them in another formula field.
- 9.
It is not possible to reference long text areas, encrypted fields, or description fields in formulas.
- 10.
It is not possible to delete fields referenced in formulas. Remove the field from the formula before deleting it.
- 11.
When you delete a child record from a rollup summary field, Salesforce does not recalculate the value of the field. Select the Force a mass recalculation option on the edit page of the rollup summary field to recalculate the value manually.
- 12.
When one validation rule fails, Salesforce continues to check other validation rules on that field, or other fields, on the page and displays all error messages at once.
- 13.
It is possible to use rollup summary fields in validation rules. However, one cannot use a rollup summary field as a location to display an error message, because rollup summary fields do not display on edit pages.
- 14.
You can create custom permissions only in the Enterprise edition or higher.
Hands-on Exercises
- 1.Configure business processes on Lead in such a way that, when users create a lead for North America or Asia Pacific, they only see the following values on lead status:
- a.
Lead status for North America
New
Suspect
Interested
Working
Qualified (Converted)
- b.
Lead status on Asia Pacific
New
Open
Qualified (Converted)
- a.
- 2.Configure the Lead Lightning record page to include the following components:
- a.
Activities
- b.
Chatter
- c.
Related List Quick Links
Assign them to the North America record type only.
- a.
- 3.Dennis Williams, a system administrator at GoC, has to meet the following requirements for the Account Name field on the Contact object:
- a.
The account name lookup dialog should only display accounts that have Mumbai as the site name.
- b.
The previous constraint should not apply to users with a system administrator profile.
How would you instruct Dennis to meet these requirements?
- a.
- 4.
Business managers at GoC found that sales reps are creating opportunities for competitors’ accounts. As an app builder, how can you restrict sales reps from selecting competitors’ accounts while creating a new opportunity?
- 5.
Create a custom field (data type: Lookup Relationship) on the Opportunity object with the Contact object. This should allow users to select a contact when creating a new opportunity.
- 6.
Keeping the previous requirement in mind, configure the lookup in such a way that it only displays the contacts related to the account with which the opportunity is associated!
- 7.Dennis wants to implement opportunity management at GoC, but he is a bit confused by one of the requirements. Because you now have a better understanding of record sharing, please help him select the appropriate sharing architecture to fulfill the following requirements:
- a.
When the opportunity amount is greater than US$1,000,000 make sure the Next Step field is required.
- b.However, make sure it doesn’t apply to the following users:
Jerry Shannon, VP Sales
Users with a system administrator profile
Users with the sales rep-APAC profile
- a.
- 8.Help Dennis to write the correct formula for the following requirements (formula field):
- a.
Create a custom field that determines the telephone country code of a contact based on the shipping country on the shipping address.
- b.
Create a custom drop-down on a contact’s preferred phone with the values Home Phone, Asst. Phone, Other Phone, and Phone. Now create a formula field that shows the phone number based on what the user provided in the Preferred Phone field.
- c.
Create a formula field that displays the first three characters of a name and year from the Date of Birth field separated by a dash.
- d.Create a formula field on Account that displays the ratings Hot, Warm, or Cold based on the following criteria:
Annual revenue should be greater than US$50,000,000.
The billing country should contain United States, US, USA, CANADA, CA, MEXICO, MX .
Now, if the account fulfills these two requirements and they belong totype Reseller, Integrator, or Partner, then the rating should be Hot
type Prospect or Investor, then the rating should be Warm
everything else, then the rating should be Cold
- e.
Create a formula field on the Opportunity object to calculate the number of days since an opportunity with an account was opened. If the opportunity is closed (either won or lost), this field should be blank.
- f.
Create a formula field on the Contact object that displays the month as a text string instead of a number from the Date of Birth field.
- g.
Create a formula field on Lead to calculate the number of days the lead has been open. If the lead is qualified or unqualified, then the formula field should be blank.
- a.
- 9.Help Dennis to write the correct formula for the following requirements (validation rule):
- a.
Create a validation rule to prompt an error message to users if a quote line-item discount exceeds 23%.
- b.
If the Phone field on the Contact object doesn’t contain ten digits, display an error message to the users.
- c.
Create the custom field Delivery Date on the Opportunity object. Now write a validation rule to make sure that this custom field must be populated if an opportunity stage is Closed Won or Negotiation/Review.
- d.
Write a validation rule to make sure the close date of an opportunity cannot be in the past.
- e.
Write a validation rule to make sure that users are only allowed to update the opportunity if they have added products to the opportunity.
- f.
Write a validation rule that prevents sales reps from changing Opportunity Stage to anything other than Closed Won or Closed Lost, after Opportunity Stage is set to Closed Won or Closed Lost.
- g.
Write a validation rule to make sure the probability of a lost opportunity is set to 0%.
- a.
- 10.
Create a custom field on Account to display the maximum amount from the related opportunity that is marked Closed Won.
Summary
In this chapter, we covered record types and how they include pages in Salesforce Classic vs. Lightning Experience. We also studied different mechanisms to improve data quality using filter lookups and validation rules. Furthermore, we reviewed rollup summary and formula fields by examining a few examples. In the next chapter, we dive into how to automate business processes using out-of-the-box automation tools.