Explore Decision Tables
Learning Objectives
After completing this unit, you’ll be able to:
- Aggregate input condition fields in decision tables.
- Transform the results of decision tables.
- Create a decision table using multiple objects as data sources.
Aggregate Input Condition Fields in Decision Tables
Consider a business scenario where you create a large number of condition fields or columns that take up a significant amount of system storage and affect ‌overall performance. So, how do you solve this complex challenge? With decision tables! Aggregate or combine condition fields for faster and simplified lookups. This aggregation optimizes performance and storage space. To use this feature, use decision tables with these criteria.
- Use the input condition columns.
- Use at least one AND condition.
- Use the Equals operator.
This enhancement helps you to create more comprehensive decision tables with increased flexibility for defining advanced and nuanced conditions. It also facilitates faster data retrieval, improved system performance, and the creation of compact decision tables.
Back to the flight aggregator example. Create a decision table and aggregate the condition fields. Use Airline Name, Source, Destination, Airline Manufacturer, Class, and AirMile Points as optional condition fields and Price as result field.
- Click
, then find and select Business Rules Engine.
- Click
and then select Lookup Tables.
- Click New.
- Select Decision Table and then click Next.
- On the New Decision Table page, specify these details.
- Name:
Flight Aggregate
- API Name: This field auto-populates with
Flight_Aggregate
- Application Usage: Default
- Decision Table Type: Low Volume
- Name:
- Click Save & Next.
- On the Condition & Results step, for Source Object, select Airline.
- In the Conditions section, click + Add Condition five times, then provide these source object fields.
-
AirMile_Points__c
-
Airline_Manufacturer__c
-
Class__c
-
Destination__c
-
Name
-
Source__c
-
AirMile_Points__c
- For the condition fields 1, 2, and 3, select Optional?
- For Condition Type, select Custom Logic, and enter
(1 AND 2 AND 3) OR (4 AND 5) OR 6
. If a Sorry to Interrupt error message window appears, click OK.
- In the Results section, for Source Object Field, select Price__c.
- Click Save & Next.
- On the Behaviours step, click Save & Next.
- On the Preview & Save step, click Finish.
- Click Activate.
When you activate the decision table, condition fields 1, 2, and 3 are joined and considered as one field. Similarly, fields 4 and 5 are joined and considered as one field. Field 6 is an independent field. This input condition field aggregation process happens in design time when you save your changes on the Condition & Results step.
During lookup, even though the active table has three condition fields, you can pass condition field values for all six condition fields. The result is based on the values passed for the six condition fields.
Transform Results in Decision Tables
Decision tables give multiple results depending on your requirements. But, what if you want to view a specific result or record instead of listing out all the results? To address this requirement, decision tables provide the Filter Result By feature. You can use this feature to transform or filter your results based on different filter criteria.
The First Match option gives you a single output. When you enter the condition details and run a rule, the decision table searches the table and fetches the values from the first record that matches your condition criteria as output.
The Any Value option searches the table based on your input conditions and gives you a single output. When your input conditions match the rows that have identical outputs, this option returns the values from one of the identical output rows. If your input conditions match the rows that don’t have identical output values, this option returns an empty response.
The Output Order is the default option in decision tables that displays all the available records that match your input condition as output. Even when you don’t select any Filter Result By option, decision tables automatically select the Output Order option and display all the matching results.
Use Multiple Objects as Data Source
Another key feature of a decision table is the usage of multiple objects as data sources. You can fetch fields from multiple objects and use them to create business rules. To add multiple data sources in a decision table, first select an object in the Source Object field as the primary data source where your main data resides. Then, add the other objects from where you want to fetch additional data in the Related Objects field.
All the objects that you’re using as related objects must have a relationship with the source object. You can select up to four objects that are related to the source object. We’ve created the Offer object with sample data in your Developer Edition org that you can use as a related object in your decision table. For the flight aggregator example, use the Airline object as source object and Offer object as related object.
Here’s the preconfigured Airlines object with its fields and corresponding data. The Offer field is fetched from the Offers object.
And here’s the preconfigured Offers object with its fields and corresponding data.
It’s time to see ‌the objects in action. Create a decision table with the source and related objects mentioned earlier. You can edit the column names only for the related object fields and not for the primary source object fields.
- Create a decision table using these details.
- Name:
Flight Offer
- API Name: This field auto-populates with
Flight_Offer
- Application Usage: Default
- Decision Table Type: Medium Volume
- Name:
- Click Save & Next.
- On the Condition & Results step, specify these details.
- Source Object: Airline
- Related Objects: Offer__c
- Source Object: Airline
- In the Conditions section, click + Add Condition, add these two source object fields.
-
Destination__c
-
Source__c
-
Destination__c
- In the Results section, click + Add Results thrice, and specify these details for the four source object fields.
- Source Object Field: Discount__c; Column Name:
Discount
.
- Source Object Field: Name (Airline__c > Offer > Offer Name); Column Name:
Offer_Name
.
- Source Object Field: Name (Airline__c > Airline Name). The Column Name field autopopulates with Name (Airline Name) as this field is a primary source object field.
- Source Object Field: Price__c. The Column Name field autopopulates with Price__c because this field is a primary source object field.
- Source Object Field: Discount__c; Column Name:
- Click Save & Next.
- On the Behaviours step, click Save & Next.
- On the Preview & Save step, click Finish.
- Click Activate.
Now, it’s time to see the decision table Flight Offer in action. We’ve created a custom Salesforce flow called Get Flight Offer in your Developer Edition org. We’ve also added the decision table to the flow with these input details.
- Source: China
- Destination: Australia
To check the results, run the flow.
- From Setup, in the Quick Find box, enter
Flows
, and then select Flows.
- Click Get Flight Offer.
- Click Debug.
- Click Run.
In the Debug Details window, notice the outputs that you had defined in the decision table earlier such as Airline Name, Price, Offer_Name, and Discount. Offer_Name and Discount fields are coming from the Offer related object. Pretty neat, right?
Wrap Up
In this module, you learned how to create a grouped decision matrix and how to use it in an expression set. You also explored the decision table and its various features. And finally, you learned how to create a decision table using multiple objects as data sources.
Congratulations! You can now configure complex business rules using decision matrices and decision tables to simplify your business processes.