Output Invocation Mapping Error in Dynamic Choices of Einstein Bots

October 2, 2018

I am sure most of you have started getting your hands dirty on Einstein Bots. If you have run into the below error when trying to build dynamic choices, welcome to the club.

"An operation invocation must contain at least 1 output invocation mapping".


A dynamic choice expects a List of values coming from the Apex Action, so you would have created a method like this

@InvocableMethod(Label = 'Get Orders')
public static List<Order> getOrders(List<String> contactIds){
//Your Logic
}

You would have assumed that this method returns a List of Orders for a given contactId. But, an Invocable method is and must be bulkified as per Salesforce Best Practices. Therefore, if you observe the input parameter for the above method, its not just a single contactId, but a List of ContactIds.

In plain English, if a contactId returns a List of Orders, then a List of ContactIds will return a List of List of Orders i.e., List<List<Order>>.

So this is how your method should actually look like

@InvocableMethod(Label = 'Get Orders')
public static List<List<Order>> getOrders(List<String> contactIds){
//Your Logic
}

Once you do this, your output section in the Bot Builder looks something like this:


For more information on Einstein Bots, download the cookbook from here - https://sfdc.co/BotsGuide I found this very helpful.