SfSkills Domains Docs GitHub

Home / agentforce / einstein-next-best-action

einstein-next-best-action

Guide practitioners through building Einstein Next Best Action strategies using Flow Builder, configuring Recommendation records, and surfacing recommendations via the Actions & Recommendations Lightning component. Trigger keywords: next best action, NBA strategy, surface recommendations. NOT for training a custom prediction model on your own records — use agentforce/einstein-prediction-builder. NOT for Einstein Bot or Agentforce agent conversation design — use architect/einstein-bot-architecture.

Open the skill folder on GitHub


Einstein Next Best Action

Einstein Next Best Action (NBA) surfaces contextual, actionable recommendations to users directly within Lightning record pages. This skill activates when a practitioner needs to design, build, or troubleshoot NBA strategies, Recommendation records, or the Actions & Recommendations component.


Before Starting

Gather this context before working on anything in this domain:


Questions to Ask Before Configuring

QuestionWhy it mattersWhat a good answer addsWhat proper configuration adds over just doing it
Which page and which component will show recommendations?The Actions & Recommendations component reads a RecordActionDeployment; without a selected deployment, reps see an empty list (Trailhead, Flow for Service setup).The deployment name, the pages, and the component placement.Recommendations appear where reps work, from one reusable deployment.
How many recommendations should a rep see at once, and in what order?The deployment shows 1–4 recommendations (maxDisplayRecommendations).A display count and a ranking rule in the strategy.The best recommendations survive the cut instead of an arbitrary subset.
Which object pages need their own strategy?deploymentContexts let up to 10 objects override the default strategy with an object-specific one.A default strategy plus per-object overrides.Case pages and Account pages get different recommendations without one giant flow.
What flow runs when a recommendation is accepted, and what should happen on reject?Recommendation.ActionReference is the flow launched on accept; IsActionActive (read-only) shows whether that flow is active; shouldLaunchActionOnReject decides whether reject also launches it.An accept flow per recommendation and a reject behavior.Accept buttons always do something, and rejects are handled on purpose.
How do recommendations expire or target an audience?The standard Recommendation object has no expiration or target-object field; those need custom fields.Custom fields such as Expiration_Date__c and Target_Object__c, filtered in the strategy.Seasonal offers retire on time and stay on the right pages.
How will responses be measured?RecommendationResponse (API 51.0+) records user responses with the action flow name and the context record.A report on responses by recommendation.Stale or ignored recommendations are found and removed.

Core Concepts

Recommendation sObject

The Recommendation standard object is the data backbone of NBA. Each record stores a Name (80 characters), Description (255), ActionReference (the flow launched on acceptance; its label is Action), AcceptanceLabel (80), RejectionLabel (80), ImageId, ExternalId, RecommendationKey, and the read-only IsActionActive flag (Object Reference). There is no standard ExpirationDate field; earlier versions of this skill listed one, and expiry needs a custom field. Recommendations are not tied to a specific record type by default; your strategy Flow handles filtering and relevance logic. Creating clean, well-named Recommendation records with clear AcceptanceLabel text ("Enroll in Loyalty Program") is critical because that label is what users see on the component button.

NBA Strategy as a Flow

Since Spring '24, NBA strategies are Autolaunched Flows (not the legacy Strategy Builder). The Flow must define an output variable of type List<Recommendation> (collection variable, sObject type = Recommendation). Inside the Flow, you query or construct Recommendation records, apply filtering and sorting logic using Decision and Assignment elements, and assign the final filtered list to the output variable. The Actions & Recommendations component invokes this Flow at page load and when manually refreshed.

Actions & Recommendations Component

This is the standard Lightning Web Component that renders recommendations on a page. You configure it in Lightning App Builder by selecting which strategy Flow to invoke. When a user clicks the acceptance button, the platform launches the flow referenced in the Recommendation's ActionReference field. The deployment's shouldLaunchActionOnReject setting decides whether a reject launches the flow too, and responses are stored as RecommendationResponse records. The component shows up to the deployment's maxDisplayRecommendations, which accepts 1 to 4. UNVERIFIED (2026-10-03): whether a rejected recommendation stays hidden for that user beyond the session is not stated in the sources read.


Common Patterns

Flow-Based Strategy with Record-Context Filtering

When to use: You want to show different recommendations based on the current record's field values (e.g., Account industry, Case priority, Opportunity stage).

How it works:

  1. Create Recommendation records for each possible action (e.g., "Upsell Premium Plan", "Schedule Renewal Call").
  2. Build an Autolaunched Flow. Add a Record Variable input of the relevant sObject type (e.g., Account).
  3. Use a Get Records element to retrieve all active Recommendation records.
  4. Add Decision elements to filter recommendations based on the input record's fields.
  5. Assign the filtered recommendations to the output List<Recommendation> variable.
  6. Place the Actions & Recommendations component on the record page and select this Flow as the strategy.

Why not the alternative: Hardcoding recommendation logic in Apex bypasses the declarative management and versioning that Flow provides, and makes it harder for admins to modify business rules without developer involvement.

Expiration-Based Recommendation Lifecycle

When to use: Recommendations are time-sensitive (seasonal promotions, limited-time offers, compliance deadlines).

How it works:

  1. Add a custom date field (for example Expiration_Date__c) to Recommendation and set it on each record; the standard object has no expiration field.
  2. In your strategy Flow, filter out recommendations where Expiration_Date__c is before TODAY, and filter on IsActionActive = true so recommendations whose flow is inactive never appear.
  3. Optionally, create a Scheduled Flow that deactivates or archives expired Recommendation records on a nightly basis.

Why not the alternative: Relying solely on manual deactivation of Recommendation records leads to stale recommendations appearing to users, eroding trust in the system.


Decision Guidance

SituationRecommended ApproachReason
Simple static recommendations (fewer than 10)Flow with Get Records + Decision elementsLow maintenance, easy for admins to modify
Dynamic recommendations based on complex scoringFlow calling an Invocable Apex action for scoring, returning sorted listKeeps scoring logic testable in Apex while Flow handles orchestration
Time-limited promotional recommendationsCustom Expiration_Date__c field + Flow filter + Scheduled Flow cleanupAutomatic lifecycle management without manual intervention
Recommendations differ by user profile or roleFlow Decision branches checking $User.ProfileId or custom permissionDeclarative segmentation without custom code

Step-by-step instructions for an AI agent or practitioner working on this task:

  1. Verify prerequisites — Confirm the Einstein Next Best Action permission set license is assigned, the Recommendation object is accessible, and the target Lightning page exists in Lightning App Builder.
  2. Define Recommendation records — Create Recommendation sObject records for each action. Populate Name, Description, ActionReference (the acceptance flow), AcceptanceLabel, RejectionLabel, and any custom fields such as Expiration_Date__c.
  3. Build the strategy Flow — Create an Autolaunched Flow. Define a collection output variable of type Recommendation. Add Get Records to pull Recommendation records, Decision elements for filtering, and Assignment elements to build the output list.
  4. Wire acceptance actions — Ensure every ActionReference on a Recommendation record points to a valid, active flow (IsActionActive = true). Test each acceptance action independently before connecting it to the recommendation.
  5. Place the component — In Lightning App Builder, drag the Actions & Recommendations component onto the target record page. Configure it to use the strategy Flow. Activate the page.
  6. Test end-to-end — Open a record that matches your strategy's criteria. Verify that the correct recommendations appear, acceptance triggers the correct action, and rejection dismisses the recommendation.
  7. Review and iterate — Check that the strategy ranks recommendations before the deployment's 1–4 display cut, expired recommendations are filtered out, and acceptance labels are clear and actionable for end users. A deployable strategy flow and RecordActionDeployment are in references/metadata-examples.md.

Review Checklist

Run through these before marking work in this area complete:


Salesforce-Specific Gotchas

Non-obvious platform behaviors that cause real production problems:

  1. Strategy Builder is deprecated — Since Spring '24, Strategy Builder is fully deprecated. Any references to Strategy Builder in documentation or existing implementations must be migrated to Flow Builder. New orgs may not have Strategy Builder available at all.
  2. ActionReference must match an active flow API name exactly: The read-only IsActionActive field reports whether the referenced flow is active. If the referenced Flow is deactivated or the API name has a typo, the acceptance button will silently fail or throw an unhandled error. There is no compile-time validation between the Recommendation record and the referenced action.
  3. Four-recommendation display cap: The Actions & Recommendations component shows at most maxDisplayRecommendations (1–4) recommendations. Rank in the strategy so the most important ones appear first. More traps, with sources, are in references/gotchas.md.

Output Artifacts

ArtifactDescription
NBA strategy FlowAutolaunched Flow returning List<Recommendation> that encodes business rules for which recommendations to surface
Recommendation recordsStandard sObject records defining each actionable recommendation with labels, descriptions, and acceptance action references
Lightning page configurationUpdated Lightning record page with the Actions & Recommendations component wired to the strategy Flow

Package files