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 Einstein Prediction Builder model training, Einstein Bots conversation design, or Agentforce agent topic routing.
Best use case
einstein-next-best-action is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
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 Einstein Prediction Builder model training, Einstein Bots conversation design, or Agentforce agent topic routing.
Teams using einstein-next-best-action should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/einstein-next-best-action/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How einstein-next-best-action Compares
| Feature / Agent | einstein-next-best-action | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
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 Einstein Prediction Builder model training, Einstein Bots conversation design, or Agentforce agent topic routing.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 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:
- Confirm the org has the "Einstein Next Best Action" permission set license assigned to relevant users, and that the Recommendation standard object is accessible.
- The most common wrong assumption is that Strategy Builder is still the tool for authoring strategies. Since Spring '24, Strategy Builder is deprecated and all NBA strategies must be built as Autolaunched Flows that output `List<Recommendation>`.
- The Actions & Recommendations component displays a maximum of 25 recommendations per invocation. Flow interview limits and Recommendation record volume can both constrain throughput.
---
## Core Concepts
### Recommendation sObject
The Recommendation standard object is the data backbone of NBA. Each record stores a Name, Description, ActionReference (the API name of the Flow or quick action to execute on acceptance), AcceptanceLabel, RejectionLabel, and an optional ExpirationDate. 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 executes the Flow or quick action referenced in the Recommendation's ActionReference field. Rejection dismisses the recommendation for that user/session. The component supports up to 25 visible recommendations at a time.
---
## 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. Set the ExpirationDate field on each Recommendation record to the date it should stop appearing.
2. In your strategy Flow, add a Decision element that filters out recommendations where ExpirationDate is before TODAY.
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
| Situation | Recommended Approach | Reason |
|---|---|---|
| Simple static recommendations (fewer than 10) | Flow with Get Records + Decision elements | Low maintenance, easy for admins to modify |
| Dynamic recommendations based on complex scoring | Flow calling an Invocable Apex action for scoring, returning sorted list | Keeps scoring logic testable in Apex while Flow handles orchestration |
| Time-limited promotional recommendations | ExpirationDate field + Flow filter + Scheduled Flow cleanup | Automatic lifecycle management without manual intervention |
| Recommendations differ by user profile or role | Flow Decision branches checking $User.ProfileId or custom permission | Declarative segmentation without custom code |
---
## Recommended Workflow
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 (API name of the acceptance Flow or quick action), AcceptanceLabel, RejectionLabel, and optionally ExpirationDate.
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 or quick action. 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 no more than 25 recommendations are returned per invocation, expired recommendations are filtered out, and acceptance labels are clear and actionable for end users.
---
## Review Checklist
Run through these before marking work in this area complete:
- [ ] Einstein Next Best Action permission set license is assigned to target users
- [ ] All Recommendation records have valid ActionReference values pointing to active Flows or quick actions
- [ ] Strategy Flow defines an output variable of type `List<Recommendation>` (collection, sObject = Recommendation)
- [ ] Strategy Flow filtering logic excludes expired recommendations (ExpirationDate < TODAY)
- [ ] Actions & Recommendations component is placed on the correct Lightning page and configured with the strategy Flow
- [ ] Acceptance actions execute correctly when the user clicks the acceptance button
- [ ] No more than 25 recommendations are returned per strategy invocation
- [ ] AcceptanceLabel and RejectionLabel text is clear and user-friendly
---
## 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 or quick action API name exactly** — 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. **25-recommendation display cap** — The Actions & Recommendations component renders a maximum of 25 recommendations. If your strategy Flow returns more, the extras are silently dropped. You must implement priority sorting in the Flow to ensure the most important recommendations appear first.
---
## Output Artifacts
| Artifact | Description |
|---|---|
| NBA strategy Flow | Autolaunched Flow returning `List<Recommendation>` that encodes business rules for which recommendations to surface |
| Recommendation records | Standard sObject records defining each actionable recommendation with labels, descriptions, and acceptance action references |
| Lightning page configuration | Updated Lightning record page with the Actions & Recommendations component wired to the strategy Flow |
---
## Related Skills
- einstein-prediction-builder — Use alongside NBA when you want AI-scored predictions to influence recommendation priority or filtering
- prompt-builder-templates — Use when recommendation descriptions or labels need dynamic, AI-generated content
- einstein-trust-layer — Relevant when NBA strategies incorporate generative AI outputs that need toxicity or PII guardrailsRelated Skills
transaction-security-policies
Transaction Security policy creation and configuration: condition builder, enhanced policies, enforcement actions (block, MFA, notification, end session), real-time monitoring mode, and policy troubleshooting. NOT for Event Monitoring log analysis or Shield Event Monitoring setup (use event-monitoring). NOT for Apex testing or debug-log analysis.
omnistudio-remote-actions
Use when configuring, troubleshooting, or choosing between Remote Action types in OmniScript or FlexCard. Triggers: 'remote action', 'OmniScript action', 'IP action', 'Apex action element', 'VlocityOpenInterface2', 'Send/Response JSON Path'. NOT for Integration Procedure internal design (use integration-procedures) or generic Apex callout patterns (use apex integration skills).
lwc-quick-actions
Use when building a Lightning Web Component that runs from a record page quick-action button — either a screen action that renders UI in a modal or a headless action that invokes logic with no UI. Triggers: 'lwc quick action on record page', 'headless quick action no ui', 'closeactionscreenevent not working', 'how to pass recordid into quick action lwc', 'quick action vs flow action', 'quick action modal size'. NOT for Flow screen components — use `lwc-in-flow-screens` — and NOT for global actions without a record context or for list-view bulk actions that do not receive a single `recordId`.
flow-transactional-boundaries
Reason about when a Flow is inside the caller's transaction vs starts its own. Pick Before-Save vs After-Save vs Async Path vs Pause + Resume when transaction boundaries matter. Covers governor-limit sharing, DML sequencing, recoverability, and the exact semantics of each Flow entry point. NOT for choosing Flow vs Apex (use automation-selection.md). NOT for Flow-to-Flow invocation contracts (use subflows-and-reusability).
flow-transaction-finalizer-patterns
Use when a Flow needs to do work that must survive the triggering transaction — post-commit notifications, callouts, audit rows, or compensating actions. Covers Flow Transaction Control element, scheduled paths, Platform Event + finalizer escalation, and Apex Queueable finalizer bridging. Does NOT cover general Flow async decisions (see async-selection).
flow-record-save-order-interaction
Reason about how record-triggered flows interleave with the Salesforce Save Order (validation, before-save flows, before triggers, duplicate rules, after-save flows, workflow, after triggers, assignment, auto-response, escalation). Trigger keywords: save order, before-save flow, after-save flow, dml order, trigger vs flow order. Does NOT cover writing trigger handlers, approval process setup, or workflow rule migration.
flow-http-callout-action
Call external HTTP APIs directly from Flow using HTTP Callout actions (no Apex), handling auth, schema, and errors. NOT for complex Apex-based integration logic.
flow-action-framework
Use when designing or troubleshooting Salesforce Flow actions in Flow Builder: standard and core actions, the Apex action element for @InvocableMethod classes, how list-shaped inputs and outputs map at the Flow–Apex boundary, subflows, and choosing between declarative actions versus custom Apex versus packaged invocables. Triggers: 'Flow Apex action', 'add Apex to Flow', 'InvocableMethod in Flow', 'Flow action palette', 'map Flow variables to Apex invocable inputs'. NOT for authoring or testing Apex @InvocableMethod bodies (use the Apex invocable-methods skill), External Services or HTTP callout registration (use flow-external-services), OmniStudio action packs, or LWC screen component local actions.
github-actions-for-salesforce
Use this skill to set up, review, or troubleshoot GitHub Actions CI/CD pipelines for Salesforce using SFDX JWT Bearer Flow authentication, Apex test gates, and branch-conditional deployments. Trigger keywords: github actions, CI pipeline, jwt auth, sfdx ci, workflow yaml, github secrets, apex coverage threshold. NOT for other CI tools such as Jenkins, Copado, Bitbucket Pipelines, or Azure DevOps.
einstein-analytics-data-model
Use this skill when working with CRM Analytics (Einstein Analytics) extended metadata (XMD) — the multi-layer metadata system that controls field display labels, aliases, number formatting, date formatting, measure/dimension classification, and color palettes on CRM Analytics datasets. Trigger keywords: XMD API, dataset field formatting CRM Analytics, wave dataset labels, main XMD update, dataset versioning Analytics. NOT for dataflow development, recipe node configuration, dataset ingestion setup, standard dashboard design, or SAQL query construction — those are covered by analytics-dataflow-development and analytics-recipe-design.
einstein-bot-architecture
Use when designing conversational AI architecture on Salesforce: Einstein Bot dialog design, Agentforce Agent topic planning, intent models, NLU training strategy, bot-to-agent handoff, escalation paths, knowledge article surfacing, and bot analytics. Triggers: 'einstein bot architecture', 'agentforce dialog design', 'bot handoff to agent', 'intent model training'. NOT for bot implementation code, Apex action authoring, Flow screen design, or Omni-Channel routing rule configuration.
fsl-custom-actions-mobile
Use this skill when building custom LWC actions for the FSL Mobile app: barcode scanning, GPS capture, photo/signature capture, or custom guided workflows on mobile. Trigger keywords: FSL Mobile custom action, lightning__GlobalAction FSL, barcode scanner LWC, mobileCapabilities, Nimbus plugin, FSL lightning SDK. NOT for standard Salesforce Mobile App quick actions, standard Experience Cloud pages, or desktop Lightning Experience LWC components.