RecommendationStrategy defines a flow-like application that selects recommendations for a client through data retrieval, branching, filtering, transformation, and ranking. It contains the selection logic and connected nodes, not the individual records queried by that logic.
A strategy is a metadata component in its own right. Its nodes and action contexts are contained structures, not independently deployable components. Although strategies resemble data flows, their metadata and node relationships should not be confused with those of a Flow component.
Key Elements
| Element | What the Element Controls |
|---|---|
contextRecordType |
The sObject type exposed through $Record. This identifies an object, not a Salesforce record type. |
onBehalfOfExpression |
A formula identifying the intended target of the recommendations, primarily for reaction tracking. The target can differ from the context record. |
isTemplate |
Whether managed-package subscribers can open and clone the strategy, then customize the clones. Defaults to false. |
name |
Within a node, its required unique graph identifier. Within other structures, this element has a different scope, such as an action-context identifier, parameter name, or recommendation field name. |
childNode |
References child nodes by their unique name values and specifies execution order. |
limit |
The inherited maximum number of results an individual node outputs. An intermediate node's limit can reduce the recommendations available to its parents. |
if |
Selects children using Boolean childNodeExpression formulas. onlyFirstMatch defaults to false, combining all matching children's results; true restricts selection to one matching child. |
mutuallyExclusive |
Returns results from the first child with nonempty output and no other child. |
filter |
Evaluates its Boolean expression for each input recommendation and retains only recommendations that evaluate to true. |
recommendationLoad |
Loads records from the sObject named by object, using constant-valued condition entries. conditionLogic combines all conditions uniformly with AND or OR. |
sort |
Orders input recommendations using field. Its nested order accepts Asc or Desc and defaults to Asc; nullsFirst defaults to false. |
map |
Assigns recommendation-field values through mapExpression entries. Each formula result must be compatible with its declared type. |
recommendationLimit |
Filters using previous reactions. filterMode accepts Accepted or Rejected; lookbackDuration gives the days searched, and maxRecommendationCount sets the reaction-count threshold. |
actionContext |
Defines named invocable-action calls whose results decision elements use. action accepts an action name or ID; name is the internal identifier used by decisioning logic. |
invocableAction |
Defines a node that calls an Apex invocable action to generate or enhance recommendations. isGenerator=true displays Generate; false displays Enhance and is the default. |
Behavior and Constraints
Metadata access
Metadata access is backed by the ManageRecommendationStrategies user permission. This is a prerequisite for managing the strategy metadata; it does not define access to every object or action the strategy uses.
Node connections and selection
The strategy's execution graph is the network of nodes connected through childNode references. These references identify nodes by name, not by label. Conditional links also identify children through childNodeExpression.childName. Renaming a node therefore affects internal links, not just display text.
Union-based nodes combine their children's outputs as their own input. The main selection mechanisms behave differently:
-
unioncombines the output of all its children. -
ifselects children using Boolean formulas. WithonlyFirstMatch=false, it combines all matching children's results. Withtrue, it selects one matching child. -
mutuallyExclusiveselects the first child that produces results. This is selection by nonempty output, rather than solely by a Boolean condition. -
filterevaluates each input recommendation separately and excludes those whose formula result isfalse.
The inherited limit applies to an individual node's output. It is not merely a final display limit: a limit on an intermediate node can constrain what reaches its parents. This output-count control is separate from the reaction-history filtering performed by recommendationLimit.
Record context and loading
contextRecordType identifies the sObject type used for $Record. Despite its name, it does not reference a RecordType metadata component. Formulas can use fields on the context record and related records, so object choice and relationship paths are part of the strategy's business logic.
recommendationLoad.object requires an sObject API name, such as Account or MyCustomObject__c. It does not identify a particular record or accept a record ID as the object name.
Each load condition contains a field, an operator, and a typed constant value. The constant's type accepts TEXT, NUMBER, BOOLEAN, DATE, DATE_TIME, or TIME. Unlike formula-bearing elements elsewhere in the strategy, load-condition values are constants.
conditionLogic applies one Boolean combination to all conditions: AND or OR. It does not express mixed grouping such as one pair of conditions joined with AND and another joined with OR.
Sorting and field transformation
A load node can order its query results through sortField. A separate sort node orders its input recommendations through field. Both use the contained StrategyNodeSortField structure, whose name identifies the field to sort. order defaults to Asc, and nullsFirst defaults to false.
Sorting, filtering, and output limits are separate controls. Their placement in the graph matters when interpreting which recommendations reach the client; sorting at one node does not make a limit on another node a final display setting.
Within map, each mapExpression.name identifies the recommendation field to assign, not the map node. Its expression must return a value compatible with type. Although type is represented as a string, its documented allowed values are BOOLEAN, CURRENCY, DATE, DOUBLE, DATE_TIME, INTEGER, LONG, PERCENT, TEXT, and TIME.
Reaction-based suppression
recommendationLimit filters recommendations using acceptance or rejection history. filterMode selects the reaction to examine, lookbackDuration defines the number of days searched, and maxRecommendationCount defines the acceptance or rejection count threshold. It is not a simple cap on the number of recommendations in one result.
onBehalfOfExpression defines the intended target of the recommendations, primarily for tracking those reactions. For example, the target can be a Contact associated with a Case even when the Case supplies the context record. The context record, intended recipient, and reaction history are distinct inputs to strategy behavior.
Invocable-action calls
actionContext and invocableAction serve different purposes. An action context defines a named call whose results decision elements use. Its action accepts an action name or ID, while its required unique name is the identifier referenced by decisioning logic.
An invocableAction node calls an Apex invocable action to generate or enhance a recommendation list. Its action identifies the action by name. isGenerator is required: true displays a Generate element, while false displays an Enhance element and is the documented default.
Both structures evaluate argument.value as a Salesforce formula and pass the result as the actual parameter value. For an invocableAction node, argument.name must match a parameter defined by the invoked action. Parameter names and result-type interpretation depend on the actual action definition, not the strategy's labels.
Deployment and Retrieval
RecommendationStrategy components use the .recommendationStrategy suffix and reside in the recommendationStrategies folder. The type supports the * wildcard in the package.xml manifest. The strategy-level label is required.
Deploy the strategy as one component containing its nodes and action contexts. A node rename must also update the applicable childNode and childNodeExpression.childName references; changing only the node's display label does not change those identifiers.
For managed-package installations, isTemplate controls subscriber visibility and cloning. With its default value of false, subscribers cannot view or clone the installed strategy because of intellectual property protection. With true, subscribers can open the strategy in a builder, clone it, and customize the clones. Template status does not imply direct customization of the packaged original.
Deploying the definition does not supply the records queried by recommendationLoad. Identical strategy metadata can return different recommendations when context records, queried data, action results, or reaction history differ.
Dependency review follows the actual objects, fields, and actions used by the strategy. An action reference can resolve to an Apex class, flow, or quick action depending on its action type; those are alternatives, not three simultaneous dependencies.
Relationships
Object dependencies arise through the context object and load-source object. Field dependencies can arise through load conditions, sort-field names, mapped field names, and field paths embedded in formulas. Not every name is a field reference: node names, action-context names, and argument names have separate scopes.
An incoming consumer can form an impact chain from RecordActionDeployment to the selected strategy and onward to its actual actions, objects, and fields. That consumer is not contained within the strategy.
References
-
ApexClass:action, when the applicable action type isapex. -
Flow:action, when the applicable action type isflow. -
QuickAction:action, when the applicable action type isquickAction. -
CustomObject:contextRecordType,object. -
CustomField:field,name, in field-bearing structures such as load conditions, nested sort fields, and map expressions. Formulas can also contain field references.
Referenced By
-
RecordActionDeployment:defaultStrategy,recommendationStrategy.
Documentation Inconsistencies
- For suffix matching in load conditions, the exposed operator enumeration uses
ENDS_WITH, while Salesforce's published operator list printsENDS_WITH=. The trailing equals sign is a serialization ambiguity when constructing metadata manually. - The declared entry element under
mapismapExpression, but Salesforce's published sample usesexpressionas the outer wrapper. Copying that wrapper literally does not match the declared element structure.
Reported Issues
-
Direct Apex SOQL inspection was reported unavailable. A 2021 community inventory listed
RecommendationStrategyamong types absent from the ApexSchemanamespace and not queryable in Apex. This report concerns Apex queryability, not Metadata API deployment or retrieval. See the Apex queryability discussion.
Common Questions
How do I retrieve all RecommendationStrategy components?
Use RecommendationStrategy as the type in package.xml with * as the member. The type supports wildcard retrieval, and its components use the .recommendationStrategy suffix in the recommendationStrategies folder. Metadata access is backed by ManageRecommendationStrategies.
Does recommendationLimit control how many recommendations are displayed?
No. recommendationLimit filters using acceptance or rejection counts over a lookback period. The inherited node-level limit controls maximum output count, including at intermediate nodes.
Why can't a subscriber open or clone a packaged recommendation strategy?
Installed managed-package strategies with isTemplate=false are protected from subscriber viewing and cloning. Setting isTemplate=true allows subscribers to open the strategy, clone it, and customize the clones, not directly customize the packaged original.
Does contextRecordType reference a Salesforce RecordType?
No. contextRecordType identifies the sObject type used for $Record. It is an object dependency, not a reference to a RecordType component.
Why does the same strategy return different recommendations after deployment?
The definition is only part of the result. Context records, queried data, action results, and reaction history can differ between executions or orgs. Deploying the strategy does not deploy the records its load nodes query.