I have a bot deployed using a chat button through a snap-ins chat. I've deployed this on a community using the snap-ins component and the bot engages fine.

I'm trying to get the Pre-chat form details using the technique in the Einstein Bot Cookbook for Beginners. The Apex class is as follows

public with sharing class HelpBot_GetPrechatDetails {

    public class PrechatOutput{
        public String sFirstName;
        public String sLastName;
        public String sEmail;
        public String sSubject;

    public class PrechatInput{
        public String sChatKey;

    @InvocableMethod(label='Get SnapIns Prechat Data')
    public static List<PrechatOutput> getSnapInsPrechatData(List<PrechatInput> inputParameters)
        String sChatKey = inputParameters[0].sChatKey;
        String sCaseId = null;
        String sContactId = null;

        List<PrechatOutput> outputParameters = new List<PrechatOutput>();
        PrechatOutput outputParameter = new PrechatOutput();
        if (sChatKey != null && sChatKey != '')
            List<LiveChatTranscript> transcripts = [SELECT Id, CaseId,
            ContactId FROM LiveChatTranscript WHERE ChatKey = :sChatKey];
            if (transcripts.size() > 0)
                sCaseId = transcripts[0].CaseId;
                sContactId = transcripts[0].ContactId;
        if (sCaseId != null && sCaseId != '')
            List<Case> cases = [SELECT Id, Subject FROM CASE WHERE Id = :sCaseId];
            if (cases.size() > 0)
                outputParameter.sSubject = cases[0].Subject;
        if (sContactId != null && sContactId != '')
            List<Contact> contacts = [SELECT Id, FirstName, LastName, Email
            FROM Contact WHERE Id = :sContactId];
            if (contacts.size() > 0)
                outputParameter.sFirstName = contacts[0].FirstName;
                outputParameter.sLastName = contacts[0].LastName;
                outputParameter.sEmail = contacts[0].Email;
        return outputParameters;

I'm getting the ChatKey fine (I send it back to the user), so I test the getSnapInsPrechatData function during the bot conversation using the following code in the developer console everything works Ok; I get all the pre-chat details OK.

HelpBot_GetPrechatDetails.PrechatInput input = 
    new HelpBot_GetPrechatDetails.PrechatInput();
input.sChatKey = '5f602e2a-d6d8-42be-a92d-6420d7c57f06';

List<HelpBot_GetPrechatDetails.PrechatInput> inputs = 
    new List<HelpBot_GetPrechatDetails.PrechatInput>();

List<HelpBot_GetPrechatDetails.PrechatOutput> results = 

When it's called by the bot however it fails to find the transcript (the chatKey was passed through fine). I thought this maybe had something to do with permissions. The sfdc.chatbot.service.permset has read access to LiveChatTranscript, Case, Contact and the Apex class HelpBot_GetPrechatDetails.

Any help would be appreciated.

1 Answer 1


This is probably because you are using Live Agent skill based routing instead of Omni-channel queue based routing.

The key difference is that skill based routing doesn't create the LiveTranscript record until after the chat has ended while Omni-channel queue based routing will create the LiveTranscript record at the beginning of the chat.

The cookbook assumes you are using Omni-channel queue based routing for this snippet to work.

  • Thanks for your answers. I had Omni channel routing turned on. I set Default Internal Access to public read only for the Live Chat Transcript in sharing settings which worked and allowed me to continue on. I probably missed a reference to this in the documentation. There might be implications for this on production systems.
    – AidanD
    Commented Jul 11, 2018 at 8:20
  • That will do it! Glad you got it working Commented Jul 11, 2018 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .