Macros in Rules
Use a macro when a single rule executes repeatedly on different JSON node paths.
Rule macros enable template developers to define repeatable, well-tested rule code units that can be called within the context of any JSON transformation, simplifying and making the rule definition source easier to maintain.
You invoke macros using standard function syntax. Reference them anywhere a traditional expression is resolved within a rule action. In template rules, macros can be referenced by an ‘eval’ action. Macros can include actions and can reference other macros, and macro recursion is supported. Template support a macro depth of 10; beyond that results in an overflow error and app creation failure.
For example, consider the following macro for multiplying two numbers:
It can be invoked in rules actions as follows:
-
Rule Macro And Macro Definition Attributes
A rule macro object contains a collection of macro definition objects. Macro definition objects define the logic of macros and their return values.
-
The following examples show the structure and syntax of macros in rules.
-
Macro Use Case: Recursive Operations
Here’s an example of a macro that deletes an
sfdcDigestnode. It also deletes the digest node and all other nodes that depend on that node. -
Macro Use Case: Delete Workflow Nodes
Use this macro to delete multiple nodes from the workflow without having to write multiple actions.
-
Macro Use Case: Add an Array of SObject Names to Extract Workflow
Here’s a macro that adds an array of
sObjectnames to the extract workflow.