---
schema_version: "1"
id: c0c2db86d03e03155f5810f3a256446d50e3f26b94924b89d3bcedea40a58cd8
title: How to Create an Expression Set That Uses Context Definition
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/bre_example_expression_with_context_definition.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.bre_example_expression_with_context_definition.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 19a87b721cf98533799f34b067cc348b1a863db46abf6321060272b38de95f5f
description: This example shows how to associate a context definition with an expression set, and how to use the local list variables in the expression set version. The example also shows how to verify if the expression set version works as expected.
products:
  - Industry Solutions
  - Cross Cloud
release: "264"
---
# How to Create an Expression Set That Uses Context Definition

This example shows how to associate a context definition with an expression set, and how to use the local list variables in the expression set version. The example also shows how to verify if the expression set version works as expected.

### Required Editions

Consider these recommendations when you design expression sets that use context definitions.

- You can save a version of a context-based expression set without explicitly marking any step as an output step, and manage the output by using the context mapping itself.
- Configure the decimal scale in the expression set version properties to correctly round off the results of the calculations that involve context variables.
- Select a context definition that does not have a reference context definition.
- Create the hierarchy of the context definition in the expression set using local list variables.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions for Industries clouds that have Business Rules Engine and Context Service enabled</td></tr></tbody></table>

To encourage writers to publish their blog posts on their platform, a new blogging platform is offering an introductory, short-term income opportunity. Blog writers are entitled to an income based on the number of views, comments, and likes for their blog posts. Each blog post published on the platform is entitled to a flat income of $10. In addition, the writers are entitled to $0.20 per like and comment, and $0.10 per view.

The platform’s marketing team asks their rule designer and Salesforce admin to create an automated rule that instantly shows the writers their earnings in real time.

The rule designer and the platform’s Salesforce admin divide the requirement into these tasks.

1. **[Create a Context Definition to Define the Blog Data Structure](https://help.salesforce.com/s/articleView?id=ind.bre_example_expression_with_context_definition.htm&release=264.0.0&type=5)**  
    The definition has the complete set of information that’s required to build the expression set to calculate the income based on the views, likes, and comments on each blog post.
2. **[Map the Definition to Data Sources and Activate the Definition](https://help.salesforce.com/s/articleView?id=ind.bre_example_expression_with_context_definition.htm&release=264.0.0&type=5)**  
    After you create the context definition, map the definition’s nodes and attributes to sObjects and their fields. The mapping feeds data into the definition.
3. **[Create an Expression Set to Calculate Blogging Income](https://help.salesforce.com/s/articleView?id=ind.bre_example_expression_with_context_definition.htm&release=264.0.0&type=5)**  
    In this example, the expression set is associated with the BlogDetails context definition. When you open the expression set version, you can use the context definition’s tags as list variables in the version’s steps.

#### See Also

- [_Salesforce Help_: List Variables in Expression Sets](https://help.salesforce.com/s/articleView?id=ind.list_variables_in_expression_sets.htm&release=264.0.0&type=5 "With the integration of Context Service with Business Rules Engine, you can use attribute tags from context definitions as list variables in expression sets and subexpressions.  An expression set or subexpression is context-aware if it is related to a context definition. When you create an expression set, select a context definition that’s available in your Salesforce org to associate the definition with the expression set. When you open a version of the expression set in Expression Set Builder, you see the context’s tags as list variables in the Resources list in the builder.")

## Create a Context Definition to Define the Blog Data Structure

The definition has the complete set of information that’s required to build the expression set to calculate the income based on the views, likes, and comments on each blog post.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
            <colgroup>
              <col style="width:50%">
              <col style="width:50%">
            </colgroup>
            <thead class="slds-text-title_caps ">
              <tr class="">
                <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d17691e171">User Permissions Needed</th>
              </tr>
            </thead>
            <tbody>
              <tr class="">
                <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e171 ">To create and activate a context definition:</td>

                <td class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e171 ">Context
                  Service Admin</td>

              </tr>
            </tbody>
          </table>

1. From Setup, in the Quick Find box, enter Context Definitions, and then select **Context Definitions**.
2. Click **New**.
3. For Name, enter BlogDetails.
4. Enter the effective start and end dates for the definition.
    
    To use a context definition in an expression set, enter a start date that’s before the expression set’s start date, and enter an end date that’s after the expression set’s end date.
5. Click **Next**.
6. To define the relationship between the definition’s nodes, create the definition’s structure.
    
    1. Add a top-level node named Blog\_Data.
        
        This node represents all attributes related to blogging data, including the child nodes and their attributes.
    2. Add a child node named Engagement\_Stats.
    
    ![Top-level node and child nodes in new context definition.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/context_service_example1.png)
7. Click **Next**.
8. Add attributes to each node, select whether the attribute is used as input, output, or both, and select the data type for each attribute.
    
    Here are the attributes in the Blog\_Data and Engagement\_Stats nodes respectively.
    
    ![Attributes in Blog\_Data node](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/context_service_example2.png)
    
    ![Attributes in the Engagement\_Stats node.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/context_service_example3.png)
9. Click **Next**, and click **Generate All Tags**.
    
    Tags appear as list variables in versions of the expression sets that are associated with context definitions.
    
    Here are the tags for the nodes and their attributes.
    
    ![Node and attribute tags](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/context_service_example5.png)
    
    ![Node and attribute tags for Engagement\_Stats](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/context_service_example4.png)
10. Save the definition.

## Map the Definition to Data Sources and Activate the Definition

After you create the context definition, map the definition’s nodes and attributes to sObjects and their fields. The mapping feeds data into the definition.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
            <colgroup>
              <col style="width:50%">
              <col style="width:50%">
            </colgroup>
            <thead class="slds-text-title_caps ">
              <tr class="">
                <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d17691e379">User Permissions Needed</th>
              </tr>
            </thead>
            <tbody>
              <tr class="">
                <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e379 ">To create and activate a context definition:</td>

                <td class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e379 ">Context
                  Service Admin</td>

              </tr>
            </tbody>
          </table>

In this example, we’re mapping the BlogDetails context definition’s nodes and attributes to the Blog and Blog Engagement custom objects, which we’ve already created. These objects have fields that are similar to the attributes in the context definition’s nodes.

1. From Setup, in the Quick Find box, enter Context Definitions, and then select **Context Definitions**.
2. To open the BlogDetails definition to map the data, select the BlogDetails from the definitions list.
3. Select **Map Data**.
4. Click **Add Mapping**.
    
    The mapping page opens on a new tab.
5. Provide mapping details.
    1. For name, enter Blog\_Readership.
    2. Enter a description.
    3. For Mapping Type, select **Automatic sObject mapping**.
    4. Select **Mark as Default**.
    5. Click **Map**.
6. Map the context definition’s nodes and attributes to sObjects and their fields.
    1. Click **Select Objects**.
    2. Search for the objects.
        
        In this example, we selected Blog\_\_c and Blog\_Engagement\_\_c.
        
        ![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/images/icon_tip.png)
        
        Tip If you can’t find a custom object, search with the object’s API name.
    3. Click **Done**.
    4. To map the nodes to sObjects, select a node and then select the object. This mapping forms a connection between the node and the object.
    5. To map attributes to sObject fields, select an attribute and then select the field.
        
        This mapping forms a connection between the attribute and the field.
        
        ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/images/icon_note.png)
        
        Note Always map the definition’s nodes before mapping the attributes.
    6. Save the mapping.
7. Return to the context definitions list.
8. To activate the BlogDetails context definition, click ![Show actions icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/show_actions_cntxt_def.png) for the definition, and select **Activate**.

Your context definition is now ready to be used in the expression set.

## Create an Expression Set to Calculate Blogging Income

In this example, the expression set is associated with the BlogDetails context definition. When you open the expression set version, you can use the context definition’s tags as list variables in the version’s steps.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
            <colgroup>
              <col style="width:50%">
              <col style="width:50%">
            </colgroup>
            <thead class="slds-text-title_caps ">
              <tr class="">
                <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d17691e620">User Permissions
                  Needed</th>
              </tr>
            </thead>
            <tbody>
              <tr class="">
                <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e620 ">To create an expression set that uses a context definition:</td>

                <td class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e620 ">Rule Engine</td>

              </tr>
              <tr class="">
                <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e620 ">To use the definition’s tags as list variables in the expression set’s version
                  steps:</td>

                <td class="slds-cell-wrap" style="vertical-align:top;" headers="d17691e620 ">Rule Engine</td>

              </tr>
            </tbody>
          </table>

1. From the App Launcher (![App explorer icon.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/app_explorer.png)), find and select **Business Rules Engine**.
2. Click the app navigation menu, and then select **Expression Sets**.
3. Click **New**.
4. Create the expression set.
    1. For name, enter Calculate\_Blogging\_Income.
    2. Select **Default** as the usage type.
    3. For context definition, select **BlogDetails**.
    4. Save the expression set.
5. From the Expression Set Versions area, select **Calculate\_Blogging\_Income V1**.
    
    The version opens in Expression Set Builder.
6. To create local list variables,
    1. Click **icon**
    2. Click **Add Resource**.
    3. In **Resource Type**, select **Local List Variable**.
    4. In **Level**, select **Node**.
    5. In **Parent Node**, select the node in the context definition.
    6. Enter the **Resource Name** and **Data Type**.
    7. **Save** your changes.
    8. Continue to create the nodes and attributes you need to use in the expression set version.
        
        The hierarchy of the local list variables appears in the list of tags for the context definition.
        
        ![Local list node variable in the Resources section](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/bre_local_list_node.png)
        
        ![Local list attribute variables in the expression set Resources section](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/bre_local_list_attributes.png)
7. Create the additional resources to be used in the version.
    1. Click **Add Resource**.
    2. For the first resource, specify these details, and click **Done and New**.
        
        Resource Type: Constant, Resource Name: Blog\_Flat\_Rate, Data Type: Currency, Default Value: 10.
    3. For the second resource, specify these details, and click **Done**.
        
        Resource Type: Variable, Resource Name: Blog\_Income, Data Type: Currency
8. Set the properties of the expression set version.
    1. To open the Expression Set Properties panel, click ![Settings icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/properties_gear_icon.png).
    2. Enter a start date time and an end date time for the expression set version.
    3. Enter a rank number.
    4. Enter a decimal scale.
        
        The decimal scale represents the number of decimal places to round off the calculation step results that involve context variables to the required precision.
    5. Close the Expression Set Properties panel.
9. On the builder canvas, add a step to calculate the number of likes per blog post by the platform’s subscribers.
    
    1. Click ![Add step icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/add_element_icon.png), and select **Calculation**.
    2. In the Formula field, search for and select **LISTSUM**.
    3. Replace ListVariable inside the parenthesis with **Like\_Count**.
    4. For Output Variable, select **Likes**.
    
    ![Tag hierarchy](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/es_with_context_example2.png)
    
    Here, Like\_Count is lower in the context definition’s node hierarchy than Likes. When the LISTSUM function sums the number of likes across subscribers per blog post, the sum is stored in the Likes variable, which is above Like\_Count in the node hierarchy.
10. Calculate the number of comments per blog post by the platform’s subscribers.
    1. Click ![Add step icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/add_element_icon.png), and select **Calculation**.
    2. In the Formula field, search for and select **LISTSUM**.
    3. Replace ListVariable inside the parenthesis with Comment\_Count.
    4. For Output Variable, select **Comments**.
11. Add the condition logic to filter blogs based on their total views, likes, and comments.
    1. Click ![Add step icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/add_element_icon.png), and select **List Group**.
    2. In the list filter, for Resource, select **Views**, for Operator, select **Greater than or Equal**, and for Value, enter 100.
        
        This expression represents the condition, Views are greater than or equal to 100.
    3. To add a condition, click **Add Condition**.
    4. For Resource, select **Likes**, for Operator, select **Greater than or Equal**, and for Value, enter 10.
        
        This expression represents the condition, Likes are greater than or equal to 10.
    5. To add another condition, click **Add Condition**.
    6. For Resource, select **Comments**, for Operator, select **Greater than or Equal**, and for Value, enter 5.
        
        This expression represents the condition, Comments are greater than or equal to 5.
    7. In the list filter, for Filter Condition Requirements, select **Custom Condition is Met**.
    8. For Custom Condition Logic, enter 1 AND (2 OR 3).
        
        The custom logic indicates that the list filter’s conditions evaluate to true when the first condition and either the second or the third condition are met.
        
        ![List filter's custom logic](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/es_with_context_example3.png)
12. Calculate the blogging income for the filtered list items.
    1. In the list group, after the list filter, click ![Add step icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/add_element_icon.png).
    2. Select **Calculation**.
    3. In the Formula field, enter Blog\_Flat\_Rate + ( 0.10 \* Views ) + 0.20 \* ( Likes + Comments ).
        
        The formula represents how the blogging income is calculated. Each blog post earns the writer a flat blog rate of $10, which is stored in the Blog\_Flat\_Rate resource. The writer is entitled to $0.10 per view on the blog post. The income from the view is calculated by multiplying the number of views with 0.10. The writer is entitled to an additional income of $0.20 per like and comment on the blog post. The income from the likes and comments is calculated by adding the number of comments and likes per post, and multiplying the number by 0.20. The income from the likes, views, and comments is then added to the blog flat rate.
    4. In the Output Variable field, select **Blog\_Income**.
        
        The Blog\_Income variable stores the output of the calculation formula for the total blog income.
13. To see a version step’s output when the expression set version runs, select the step element, click ![Element details icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/elements_panel_icon.png), and select **Include in output**.
14. Save the version.
15. To verify that the steps work as expected, simulate the version.
    1. Click **Simulate**.
    2. For Input Mode, select **Advanced**.
        
        When you use list variables in an expression set, always use the Advanced input mode to pass sample values for simulation.
    3. Modify the JSON input template with these sample values.
        
        ![JSON input example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/example_sample_json.png)
    4. Click **Simulate**.
        
        The list filter returns one matching result based on the filter criteria.
        
        ![Simulation result from the list filter](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/simulation_list_filter_result.png)
        
        The calculation step in the list group returns the blogging income for the blog post that meets the filter conditions.
        
        ![Simulation results from the calculation step in the list group](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-business_rules_engine-264-0-0-production-enus/b2d6dd5c-c231-428b-abbf-3dd2cd51a11f/business_rules_engine/images/simulation_list_group_calculation.png)