Skip to main content
Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

Set Up an Expression Set

Learning Objectives

After completing this unit, you’ll be able to:

  • Describe how to access data from Salesforce objects and fields as variables in expression sets.
  • Create expression sets.
  • Create resources.
  • Add elements to an expression set.

Access Object Data Using Aliases

Zercovana also provides subsidies based on annual income to ensure that those with lower incomes can also afford health insurance. Since Zercovana went digital and seized the Salesforce advantage, annual income information is now available in the Annual Income field in the Contact object of all the applicants. Jessica can use that data to calculate the income-based subsidy. 

So, instead of asking the applicant to enter the data and then verifying it against Zercovanian records, Jessica can simply fetch it from the Contact object of the applicant while calculating the subsidy. Nifty, right?

But there’s a catch. It’s not possible to fetch data directly from Salesforce objects and fields to use them in expression sets. Instead, use object and field aliases to reference the Salesforce objects and fields. Then use the aliases to fetch the required data.

Only admins have permission to create object and field aliases. So, Jessica asks her Salesforce admin to help set up access to the Birthdate, Annual Income, and Disability fields in the Contact object. Her helpful Salesforce admin creates an object alias for the Contact object and the corresponding field aliases. To learn more about how to create object and field aliases and use them in expression sets, refer to Object Variables in Expression Sets.

Here are the specific aliases Jessica needs.

Object Alias for the Contact object

Field Name

Field Alias

Data Type

Description

InsurancePremium

Birthdate

ApplicantBirthdate

Date (MM/DD/YYYY)

Used to fetch the birthdate of the applicant and calculate their age

Annual Income

ApplicantIncome

Currency

Used to fetch the annual income of the applicant

Disability

DisabilitySeverity

Text

Used to check whether the applicant has a disability and the severity of their disability

These object and field aliases are already available in your org. See them in action when you use expression sets in the next section.

Build an Expression Set

Expression sets are how you orchestrate the magic in Business Rules Engine. After creating the decision matrices, Jessica’s now eager to use the Expression Set Builder to create an expression set version. Zercovana uses expression sets to calculate the subsidy percentage an applicant receives. 

  1. Click App Launcher, then find and select Expression Sets.
  2. Click New.
  3. In the New Expression Set window, enter these details:
    • Name: Insurance Premium Calculation
    • API Name: This field auto-populates with Insurance_Premium_Calculation
    • Usage Type: Default
  4. Click Save.

Your expression set is now created and ready to be configured.

Create Resources

Jessica’s next task is to create resources. Resources are of two types: variables and constants. In expression sets, you can use a Variable resource type to store dynamic values. Use the Constants resource type to store fixed values. To calculate the final insurance premium, Jessica just needs the variables.

Follow along to create the variables.

  1. On the Insurance Premium Calculation expression set record page, click Insurance Premium Calculation V1 to open the expression set version in the Expression Set builder.

Expression set record page with the Insurance Premium Calculation V1 expression set version highlighted.

  1. Click Resource Manager to open Resource Manager.
  2. Click Add Resource.
  3. In the Add New Resource window, enter these input values for the Disability Severity variable. This variable captures the disability severity status of the applicant.
    • Resource Type: Variable
    • Resource Name: DisabilitySeverity
    • Data Type: Text
  1. Click Done And New.
  2. Repeat the steps 4 and 5 to create the rest of the variables in this table.

    Resource

    Description

    Input Values

    Applicant Age

    Age of the applicant using the birth date fetched from the Contact object

    Resource Type: Variable

    Resource Name: ApplicantAge

    Data Type: Number

    Decimal Places: 0

    Total Subsidy

    Sum of all the subsidies that are applied based on the applicant’s eligibility

    Resource Type: Variable

    Resource Name: TotalSubsidy

    Data Type: Percent

    Decimal Places: 2

    Discounted Premium

    Premium amount after deducting total subsidy from the family premium

    Resource Type: Variable

    Resource Name: DiscountedPremium

    Data Type: Currency

    Decimal Places: 2

    Final Premium

    Value of the insurance premium after applying all the subsidies and discounts

    Resource Type: Variable

    Resource Name: FinalPremium

    Data Type: Currency

    Decimal Places: 2

  1. Once you’ve added all the variables, click Done.
  2. Click Save.

All the required variables are now ready for you to use it in the expression set.

Add Step Elements to the Expression Set

Jessica quickly captured all the required variables. She rubs her hands in excitement as the next step is to build the expression set using step elements such as lookup tables, branches, and calculations.

Calculate the Family Insurance Premium Amount

To calculate the insurance premium amount for a family, Jessica adds the Base Premium lookup table. This lookup table uses the number of dependents of the applicant as input and provides the family premium as output. 

  1. In the Expression Set Builder canvas for Insurance Premium Calculation V1, click Add component.
  2. Find and select Lookup Table.
  3. In the Lookup Table Details field, find and select Base Premium.
    The Base Premium lookup table.

Calculate the Disability Severity and Veteran Status Subsidy Percentage

The disability severity status of an applicant is captured from a custom field in the Contact object using the field alias named DisabilitySeverity. The field alias is always prefixed by the object alias, such as InsurancePremium.DisabilitySeverity, where InsurancePremium is the object alias for the Contact object.

Now, the value from the field alias is mapped to the output variable DisabilitySeverity that was created earlier. The DisabilitySeverity variable allows the disability status from the field alias to be used in the calculations in the expression set.

  1. In the Expression Set Builder, click Add component after Base Premium lookup table element.
  2. Find and select Calculation.
  3. Click the Calculation name and rename it to Disability Severity.
  4. For Formula, type Insurance and select InsurancePremium.DisabilitySeverity.
  5. For Output Variable, find and select DisabilitySeverity.
    The Disability Severity calculation element.

To calculate disability severity and veteran status subsidy percentage, Jessica adds the Additional Subsidy lookup table. This lookup table uses the applicant’s disability severity and veteran status as inputs and calculates the subsidy percentage. 

  1. In the Expression Set Builder, click Add component after Disability Severity.
  2. Find and select Lookup Table.
  3. In the Lookup Table Details field, find and select Additional Subsidy.
    The Additional Subsidy lookup table.

Calculate Applicant Age and Apply Age Related Subsidy

Jessica now calculates the applicant’s age using their birth date. She does this by using the object field alias that Zercovana’s Salesforce admin has already created for the Birthdate field in the Contact object. After calculating the age of an applicant, she assigns the value to the ApplicantAge variable. This variable is used as input in the age related subsidy lookup table that she adds next.

To calculate the applicant’s age, she uses the AGE function. 

  1. In the Expression Set Builder, click Add component after Additional Subsidy and add a Calculation element.
  2. Click the Calculation name and rename it to Applicant Age.
  3. For Formula, enter AGE ( InsurancePremium.ApplicantBirthdate ).
  4. For Output Variable, find and select the ApplicantAge variable.
  5. Save your work.
    The Applicant Age calculation element.

Jessica then adds an age-related subsidy lookup table to the expression set to calculate the subsidy based on the applicant’s age.

  1. In the Expression Set Builder, click Add component after Applicant Age.
  2. Find and select Lookup Table.
  3. In the Lookup Table Details field, find and select Age Related Subsidy.
  4. Save your work.
    The Age Related Subsidy lookup table.

Calculate the Total Subsidy Percentage

Next, Jessica adds all the subsidy percentages to calculate the total subsidy percentage an applicant gets. First, she adds a calculation element and a formula. Then, in the output variable field, she adds the TotalSubsidy variable to capture the total subsidy percentage.

To perform this calculation:

  1. Click Add component after Age Related Subsidy and add a Calculation element.
  2. Click the Calculation name and rename it to Total Subsidy.
  3. For Formula, enter Additional_Subsidy__Subsidy + Age_Related_Subsidy__Subsidy.
  4. For Output Variable, find and select TotalSubsidy.

The Total Subsidy calculation element.

  1. Save your work.

Calculate the Discounted Premium Amount

Next, Jessica calculates the discounted premium amount after deducting the total subsidy from the base premium amount.

Follow the steps to add a calculation element and a formula to do the calculation. Then, in the output variable field, add the DiscountedPremium variable to capture the total discounted premium amount.

  1. Click Add element after Total Subsidy and add a Calculation element.
  2. Click the Calculation name and rename it to Discounted Premium.
  3. For Formula, enter Base_Premium__FamilyPremium - ( TotalSubsidy * Base_Premium__FamilyPremium ).
  4. For Output Variable, find and select DiscountedPremium.
  5. Save your work.
    The Discounted Premium calculation element.

After calculating the subsidy on the base premium, the results are stored in the Discounted Premium variable.

What’s Next

In this unit, you learned how to create an expression set and add step elements to the expression set. In the next unit, explore how to add a branch with conditions to the expression set.

Resources 

Hands-on Challenge

+500 points

Get Ready

You’ll be completing this unit in your own hands-on org. Click Launch to get started, or click the name of your org to choose a different one.

Your Challenge

Create Resources and Add Elements to an Expression Set
Add the Applicant Age Based Subsidy lookup table element, create the TotalDiscount variable, and add a calculation element to capture the total discount.
  • Open the Insurance Payment V1 expression set version in the Expression Set Builder. Then, add the Applicant Age Based Subsidy lookup table element after Applicant Age in the expression set builder.
  • Create a variable:
    • Resource Type: Variable
    • Resource Name: TotalDiscount
    • Data Type: Percent
    • Decimal: 2
  • Add the Total Discount calculation element after Applicant Age Based Subsidy.
    • Rename the calculation element to Total Discount
    • Formula: Additional_Subsidy__Subsidy + Applicant_Age_Based_Subsidy__Subsidy
    • Output Variable: TotalDiscount
Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback