2

We have a requirement to show previous transcripts history(from Live Agent) in a custom field .How I can achieve this.Or is there any other alternative to show transcript history in the object record.?

1 Answer 1

2

I've made trigger on LiveAgentTranscript object for that, no idea if there's a better way and if you're OK with having to code a bit yourself... I find Agent's documentation pretty scarce.

My rough flow goes like this:

  1. Visitor fills in the prechat window with some basic stuff (First Name, Last Name, Email, optionally Case Number if it's "I'm contacting you with regards to Case X")
  2. I'm trying to find that Case / raise new one and find / create new Contact.
  3. Chat session with the CaseNumber__c field mapped with that Case's number is eventually accepted.
  4. Chat finishes, transcript gets saved. My trigger fires.

trigger workaround on LiveChatTranscript (after insert) {

    Set<String> caseNumbers = new Set<String>();
    for(LiveChatTranscript lct : trigger.new){
        caseNumbers.add(lct.CaseNumber__c);
    }
    caseNumbers.remove(null);

    if(!caseNumbers.isEmpty()){
        Map<String, Case> cases = new Map<String, Case>();
        for(Case c : [SELECT Id, CaseNumber FROM Case WHERE CaseNumber IN :caseNumbers]){
            cases.put(c.CaseNumber, c);
        }

        List<Case> casesToUpdate = new List<Case>();
        List<CaseComment> comments = new List<CaseComment>();

        for(LiveChatTranscript lct : trigger.new){
            Case c = cases.get(lct.CaseNumber__c);
            if(c!= null){
                c.Live_Chat_Transcript__c = lct.Id;    // Fill in the lookup
                comments.add(new CaseComment(          // Add the transcript
                    ParentId = c.Id,
                    CommentBody = lct.Body.abbreviate(3500)
                ));
            }
        }
        if(!casesToUpdate.isEmpty()){
            Database.update(casesToUpdate, false);
            Database.insert(comments, false);
        }
    }
}

There might be better ways, I admit I've just force hacked my way through the Live Agent and it's just a prototype code...

For example you could save the Case Id directly on the Transcript so you don't have to query. I've tried to do that but found out that the Id then displays in the agent's window which looks bit rubbish; Case Number is more human-readable even if agent can't click it (I've opened the Case for him in one of the subtabs when he accepted the chat so whatever).

Comment is abbreviated to 3500 chars because even though the field's limit is 4000 I've been running into some problems there (UTF encoding probably? multi-byte characters?).

It's also a simple, butt-ugly dump of the HTML, you'll have to spend some time parsing it or try how it looks when dumped to RTF field...

5
  • As you explained ,I'm also working on the same scenario is 'trying to find that Case / raise new one and find / create new Contact' ...If you could provide 'Code' for this approach,getting stuff from visitor from prechat fields are First Name, Last Name, Email, Case Number..It would be great helpful for me.
    – User1511
    Jun 26, 2014 at 20:05
  • Can you search a bit around (for example check salesforce.stackexchange.com/questions/23129/…) and post this as separate question if you're still stuck? I'm even less sure whether I did that bit "the right way", there was lots of trial & error involved. It's likely somebody will see it and post a better answer or explain what misconceptions I had ;)
    – eyescream
    Jun 26, 2014 at 20:26
  • Peter Knolle wrote a great article on building a pre-chat form here: peterknolle.com/live-agent-pre-chat-api @eyescream - to answer your particular issue with the CaseId showing to the agent, Peter doesn't list it in his article, but you can use liveagent.prechat.findorcreate.displayToAgent in a similar fashion to saveToTranscript to hide the value from the agent. Jun 26, 2014 at 21:07
  • Hi eyescream,I followed the code which you have suggested.But here I've some doubts,Is this field 'CaseNumber__c' has to create manually on 'Transcipts' objects ?
    – User1511
    Jul 1, 2014 at 11:02
  • Yes, you'd have to create a custom fields and make sure it's populated it in the prechat mapping logic (either in the input fields or in the javascript function calls).
    – eyescream
    Jul 1, 2014 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.