function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PlainviewPlainview 

Assign Live Agent Chat Leads to Agent/User who conducted the Chat.

Assigning Live Chat Leads to Reps who handled the Chat:

For live chat leads, is there a way for the leads generated by the Live Agent Chat to be assigned to the sales rep. that picks up the chat? Currently in our org., if a rep./user picks up a chat and handles it, it gets reassigned to a Sales Manager, who then has to assign it back to them.

Thanks!

Julien
ShashForceShashForce
You should first determine how the owner is changing to the Sales Manager.

1.) If it is through a trigger, consider changing the trigger.
2.) If it is because of the Sales Manager being a default lead owner or something, consider adding a trigger on the Live Chat Transcript object.
PlainviewPlainview
Hello!

Thanks for your response. We currently have only two Live Agent Triggers, as follows. Can you see anything in these that could be revised?


trigger LiveChatTranscriptUpdateLead on LiveChatTranscript (before insert, before update) {

  //build a map where the key is the LeadId and the value is the new ownerID 
  Map<Id, Id> leadOwnerMap = new Map<Id, Id>();
 
  for (LiveChatTranscript ts : Trigger.new) {
    if (ts.LeadId != null) {     
      leadOwnerMap.put(ts.LeadId, ts.OwnerId);
    }
  }
 
  if (!LeadOwnerMap.isEmpty()) {
    LeadUpdateOwnerChat.updateLeadOwner(leadOwnerMap);
  }

}

And ...

trigger LiveChatTranscriptUpdateContactAndCase on LiveChatTranscript (before insert, before update) {


  //build 2 maps
  //they both have the LiveChatTranscript ID as the key
  //one has the value of any Case ID, and the other has the value of any Contact Id
  Map<Id, Id> transcriptCaseMap = new Map<Id, Id>();
  Map<Id, Id> transcriptContactMap = new Map<Id, Id>();
 
  for (LiveChatTranscript ts : Trigger.new) {
    if (ts.CaseId != null) {     
      transcriptCaseMap.put(ts.Id, ts.CaseId);
    }
    if (ts.ContactId != null) {     
      transcriptContactMap.put(ts.Id, ts.ContactId);
    }
  }
 
  if ( (!transcriptCaseMap.isEmpty()) || (!transcriptContactMap.isEmpty()) ) {
    //doSomething(transcriptCaseMap, transcriptContactMap);
  }
ShashForceShashForce
The second trigger is not doing anything.

The first Trigger updates the Lead owner, but the major chunk of the code lies in the "LeadUpdateOwnerChat" apex class which is being called by the trigger. We should look at that class code as well to understand.
PlainviewPlainview
Thanks again for continuing to go on this ride with me. Here's the code from the apex class LeadUpdateOwnerChat;

public class LeadUpdateOwnerChat {

  static final Id SALES_SITE_GUEST_USER = '00500000007CVPw';

  @future
  public static void updateLeadOwner(Map<Id, Id> leadOwnerMap) {
    //map coming has the key as the lead id and the value as the new owner id   
   
    //Id saleSiteGuestUser = '00500000007CVPw'; //leads created by the chat will have this owner
   
    //build a list of the Leads we need to change the owner on
    if (!leadOwnerMap.isEmpty()) {
      List<Lead> leadList = new List<Lead>();
      leadList = [SELECT Id, OwnerId FROM Lead WHERE Id IN: leadOwnerMap.keySet() AND OwnerId=: SALES_SITE_GUEST_USER];
      if (!leadList.isEmpty()) {
        for (Lead l : leadList) {
          l.OwnerId = leadOwnerMap.get(l.Id);
        } 
        updateEmailPrefsAsync.inFutureContext = true;
        update leadList;
      }     
    }
  } 
 

   static testMethod void doTest() {  
       
     //create a test Lead
    Lead testLead = new Lead(OwnerId = SALES_SITE_GUEST_USER,   
                FirstName = 'John',
                LastName = 'Smith',
                Email = 'test@test.com',
                LeadSource = 'Corporate Website, Live Chat',
                Company = 'ACME');
    insert testLead;
    update testLead; 

   
    //create a test sales rep
    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
    User u = new User(Alias = 'test4a6', Email='standarduser@testorg.com',
    EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
    LocaleSidKey='en_US', ProfileId = p.Id,
    TimeZoneSidKey='America/Los_Angeles', UserName='test4a6@test4a6.com'); 
    insert u;
    update u; 

    Map<Id, Id> leadOwnerMap = new Map<Id, Id>();
    leadOwnerMap.put(testLead.Id, u.Id);

    Test.startTest();
   
    updateLeadOwner(leadOwnerMap);
   
    Test.stopTest();

       
   }



}
PlainviewPlainview
... We also have a lead assignment rule that might be mucking things up. The rule filters all leads from our various sources and routes them to our Sales Manager. I added a custom field to the Lead object called "Live Agent Lead" (a checkbox) and add an additional filter to the rule "Lead: Live Agent Lead equals false" in the hope that this will help the issue.


PlainviewPlainview
... and a bit more.

I've been instructed by Salesforce support to add some logic to the code that says, "If Lead comes from Live Agent Chat, update the check box to true, record is retained to the Chat rep."

I have created a custom checkbox field on the Lead Object (Live Agent Lead) and am wondering what the logic would look like and where to insert it in the code.

So far, I have:

if (!LiveAgentLead.isEmpty()) {
LeadUpdateLiveAgent.updateLiveAgentLead = true;
}

... but am having difficulty fleshing it out and placing it.

Any guidance is greatly appreciated.

Thanks,
Julien