Building a Scheduled Alert Generator with Next Best Action and Flow

Suppose that you have an NBA recommendation strategy that runs on Account record pages, generating insights and recommendations specific to a given account. Your salespeople have 50 accounts, and they don’t want to have to manually visit every account page each day to see if there’s something new waiting for them there. What do you do?

Watch the Video


In this solution, we create a two part process. Every night a scheduled flow runs that kicks off a recommendation strategy for every active Account in the organization. This might take a long time and a lot of processing power, but we’re doing it in the middle of the night and can spread it out if we run into any load issues. When the flow gets the results back for a given account, it is only concerned with the _count_ of recommendations. If at least one recommendation has been returned, it marks that Account record by setting to True a boolean Account field called HasAvailableInsight__c. The recommendations themselves are discarded.

When the salesperson starts work the next morning, instead of visiting an Account page, they visit their Home page, where a different NBA strategy is running. This strategy generates a recommendation for each Account that has an available insight. This provides the user with an effective task list of accounts to check. They can click on a recommendation to take them directly to that account page, where the original Account strategy will present them with useful insights.

You can install the package provided here, which consists of the Scheduled Flow that runs at night, the two sample NBA strategies, and the action flow that navigates the user from the NBA component on the Home page to the appropriate Account page.

How It Works

Here’s the Scheduled Flow that runs each night:

This scheduled flow starts by loading the desired set of accounts. It loops over them, running the Execute NBA Strategy flow action against each account. (Note that this flow action is included in this package). This flow action has been enhanced to return a count of the number of recommendations, and this count is used in a decision element to determine whether the HasAvailableInsight__c field should be set to true or false. After the looping is complete, the updated accounts are saved.

Here’s the configuration of the flow action:

The Home page looks like this:

Here’s the strategy that runs on the Home Page:

The account records are mapped into recommendation objects with this configuration:

To navigate the user to the appropriate account page from the home page, the Navigate Everywhere flow action is used.

The final strategy that runs on the Account page can be anything you want, but you obviously want it running the same analysis that the nightly scheduled flow runs.


Not yet available as a package.

View Source


NBA – Best Practices

Best Practices (Strategic)

  1. Whiteboard! Whiteboard! Whiteboard!
    •  Spend time in determining
      • What: are the use cases? 
      • Who:  are the recommendations for- is it for the end customer or is it for the agent themselves?
      • Why: do you want these recommendations? what  are the target KPIs 
        • A few common target KPIs
          1. Agent productivity
          2. CSAT
          3. NPS
          4. Revenue
          5. Conversions
          6. Closing rate
          7. Cost savings
      • When: to surface ? What  are the key touch points? 
        1. Inbound communication – customer call
        2. Stages of the Purchase funnel
      • DATA: Recommendations are only as good as the data! 
  2. Start small and build up more complex use cases
    • Start with 1 or 2 use cases
    • Seed the recommendation system with only business rules, then augment with AI
  3. Make use of OOTB Reporting 
    • The NBA OOTB reporting infrastructure helps evaluate how your strategies are performing, # of accepts,rejects etc

Best Practices (Tactical)

  1. Categorize recommendations- easier to manage
    • Add a category field to the Recommendation object 
  2. Make sure flows that are invoked upon accept /reject are built and activated 
  3. Split strategies rather than having a giant monolith strategy*.
    • *Current limitation is that there is a 1:1 mapping with the display component and the strategy it executes but versioning and sub-strategies are on the roadmap. 
    • Using the Generate node to split strategies work today. 
  4. Requests consumed can be viewed under Company Information 

Some common issues and workarounds

  • Reporting and Limit Reoffers on Dynamic Recommendations
    • Recommendation Id is not persisted when using dynamic recommendations with the generate node. Read this blog post for workaround
  • Advanced Formula Support: The Load node doesn’t support dynamic formulas or $Record because under the covers Load node is a SOQL query and does not execute formulas, but use the Filter/Branch node to freeform write formulas and access $Record and formula fields. 
    • Navigate to the advanced tab of the Filter/Branch node for advanced formulas such as shown
    • All standard salesforce operations are evaluated in the advanced tab including $Record.
Use of the advanced tab to write a filter expression using $Record and the OR operator.

Reporting on dynamic recommendations created by the Generate node

When using a Generate node to create dynamic recommendations, you need to ensure that the ID for the recommendation is passed because that is the primary key on which the node operates and further downstream reports are generated.  A point to watch out for is that it is not straightforward to generate IDs dynamically and be assigned to the recommendation object because Apex is strongly typed and would look for an ID of type Recommendation. 

However, there are several recommended workarounds for this situation. 

  1. If your use case can instead use the load node to load an SObject (vs a recommendation object) and then map the fields such as Id, name, accept label, reject label and flow name in a map node as shown below.
Using the Map node to map required fields on the Recommendation object
Using the Map node to map required fields on the Recommendation object

If this doesn’t work because of the dynamic nature of your use case and the Generate node needs to be used to programmatically create recommendations, another way to tackle it is as below.

Say the recommendations are mapped by querying a product object in the Apex class. You can assign the ID field of the object queried to the External ID field of the recommendation object created. This avoids the ‘Strong type’ checking of the ID issue. Following is a code snippet from a Generate node.

And then use the map element in the strategy following the generate element to map the external ID to the ID of the recommendation object. 

Use a Map node to map the external Id to Recommendation Id

Create a Next Best Action Employee App – Part 2

Setup and Installation steps (View Part 1 for demo video and details on the building blocks)

STEP 1: Install package


STEP 2: Setup the environment

  • Make sure all custom fields on the User object are accessible and visible in the page layouts
  • Object Manager →User →Fields & Relationships
  • Navigate to each of the fields below and follow the steps to Set Field Level Accessibility to Visible to all profiles
    • Navigate to each of the fields below and follow the steps to Set Field Level Accessibility to Visible to all profiles
      • Einstein HiPo Likelihood
      • Next Shift Start Date
      • Next Shift End Date
      • Is People Manager
      • Survey Taken

Screen Shot 2020-06-25 at 11.43.37 AM.png
  • Ensure that the fields are visible in the default page layout
  • Go to object manager – User page layouts. Drag the custom fields to the Additional Information Section
  • Repeat for Message layout →Drag the Category field appears in the detail page

STEP 3: Create Users of the app.

  • User1
    • First name Bessie
    • Last Name Thomas
    • use your email for email and
    • give a username such as
    • In additional information
      • Check Is People Manager
      • Add dates for Next Shift Start and Next Shift End Dates
      • Leave the Survey Taken column unchecked
  • User2 (Important to use the same name as for the purpose of the demo , it is hard coded)
    • First name Rosa
    • Last Name Garcia
    • use your email for email and
    • give a username such as
    • In additional information
      • Leave the Is people manager unchecked
      • Leave the Survey Taken column unchecked
      • Give a value >80% to simulate Einstein HiPo Likelihood
      • Add dates for Next Shift Start and Next Shift End Dates
  • Make sure to remember the username and also change the password. (You should receive an email on the registered email)

STEP 4: Assign permissions

  • Go to users – permission set and enable both Goodmorning and Goodmorningsales permission for the user user(user user is the admin user for scratch orgs)
    • Permission set →Manage Assignments→ Add Assignments→ User, User (if scratch org or the relevant users) .
  • Profiles→system admin→ change permissions to view object (Assuming both users are System Administrators. If not assign the following permission accordingly to the users created)
    • custom app setting →check bright team management
Screen Shot 2020-06-25 at 11.52.01 AM.png

STEP 5: Add Data to custom objects

  • Go to SalesTacticalPlan object from the AppMenu (If it does not show – make sure the user permissions are set)
  • Create a record with the details shown (EmployeeDailyTacticalPlan)

  • Create the following records to the Recommendation object
  • If you do not see any field visible on the recommendation object : Go to Recommendation object Manager→Page Layout→Manage Assignment →Edit Assignment and assign recommendation layout to all users.
 NameDescriptionAction Reference Acceptance LabelRejection Label
1Priority Message: Tax DayTax day is in 6 weeks! Get more detail.Tax_FlowAcceptReject
2Priority Message: Well Being SurveyOur records indicate that you have not taken the Well Being Survey. Please take a few minutes to complete it.Well_Being_Survey_FlowAcceptReject Contact Risk AlertAlert! You have recently come in contact with someone who has tested positive for COVID -19. Please contact the health center for more details.Contact_RiskAcceptReject
4Return to Work Shift Days Shift_FlowAcceptReject
5Training RecommendationYour manager has identified that you will benefit from the Great Salesforce Leaders training. Click to enroll.Enrollment_FlowAcceptReject

STEP 6: Set up the flow component to accept input for which messages and their respective priorities to be surfaced on the NBS Component

  • Navigate to the Bright Team Mgmt App from the App Menand then user profile(click on the profile pic icon) and then edit page to bring up LAB. NOTE: If you click on user profile when on setup , you go to User setup not the profile page so make sure you are on the app when pulling it up
    • Drag the Flow component and choose Manage Employee Tactics as shown below
Screen Shot 2020-06-25 at 11.54.52 AM.png

Drag a flow component.Choose the manage tactical plan. activate it for the org default

  • Go to the Bright Team Mgmt app and then user profile(click on the profile pic icon) and then edit page to bring up Lightning App Builder — if clicking on user profile when on setup pulls up