Category: Live Agent

Lightning Console disabling tab closing

In this blog, I will show one of the coolest features of the console to disable the close record action on Lightning experience. In this example, if any high priority cases are created, case description is required to close the tab otherwise we will be disabling the close icon on the tab. we can use a console API to prevent agents from closing tabs until they’ve completed all required work on a case. The console API  can disable a tab from closing using the disableTabClose method. You can prevent tabs from being closed in two ways:
  1. Disable a primary tab. Its subtabs remain unlocked unless disableTabClose is invoked on them individually.
  2. Disable a subtab. This also disables its enclosing primary tab.

disableTabClose is fully supported when you click the close-tab icon or when invoked via API. Other ways of invoking it aren’t fully supported and may not behave as you want them to. Macros aren’t fully supported. If disableTabClose is invoked via a macro, the error message might not appear, but the agent still won’t be able to close the tab in most cases. And of course, we can only lead a horse to water. An agent can still close the browser window. But hey, can’t say we didn’t try!

Tab behavior when records are deleted

When a primary tab is disabled and its record is deleted, that whole set of tabs (primary + subtabs) automagically closes.

When a subtab is disabled and its record is deleted, the subtab remains open but refreshes as a blank tab (although any sidebar components will render).


Here is the simple code.


Include this component on Lightning Record Page 

Now add the DisableTabClose.cmp to the record page anywhere as shown below 


Now open any high priority record without description .the close tab button is disabled as shown below.

Now open any high priority record with description .the close tab button is enabled as shown below.

Live Agent Deployment API


In this blog, I am going to explain how to use the live agent deployment API  to find and create records and how to customize chat buttons and chat window. Live agent deployment API has the number of options to customize the live agent like Logging and controlling the live agent online and offline behaviors and allow automatically creating records and suggest the knowledge article etc. Below is the code from where you will launch your live agent normally it might be your webpage or visual force page from sites etc.

Understand the code

Live agent logging will be very useful if you wanted to troubleshoot the live agent. You can enable the Logging by simple liveagent.enableLogging(); the method which results in the debugging as shown below on browser console.

The below piece of code shown what to do when the agent is online or offline.The showWhenOnline or showWhenOffline method to specify customers see when a particular button is online or offline based on the agent status. the below code we specify the button id to show the status  liveagent_button_online_5736A000000gBrn , liveagent_button_offline_5736A000000gBrn  .

The below code request a chat from a button in a new window when you click on chat button by calling liveagent.startChat method.

Find and Create Records
Use the Deployment API to search for or create Salesforce records like a case, contact, account, or lead automatically when an agent begins a chat with a customer.addCustomDetail methods as  Adds a new custom detail for the chat visitor.

The Custom Detail is displayed to agents in the footer widget and in the Chat Details page in the Salesforce Console while the chat is active as shown below.


Use the findOrCreate method to find existing records or create new ones based on certain criteria. The findOrCreate method begins the API call that finds existing records or creates new records when an agent begins a
chat with a customer. The below code show to find and create records and store it to the live agent transcript and suggesting the knowledge articles.

In the above code, we are trying o find the contact and if not available the create a new contact also searches for records that contain customer data specified by the addCustomDetail Deployment API method.  findOrCreate.saveToTranscript method to save the record you find or create the chat transcript associated
with the chat. Use the findOrCreate.showOnCreate method to automatically open the record you create in a subtab in the Salesforce console.   findOrCreate.linkToEntity method to link the record you found or created to another record type. The below image shows the search results on the console chat


liveagent.addCustomDetail(‘Case Subject’,’Refund policy for products’).doKnowledgeSearch() method search for Knowledge articles as shown below when customer is chat with agent.




Live agent Pre-Chat Forms with Validations


In this post, I am going to explain how to set Pre-Chat form to collect information from visitors and customers the pre-chat page as well.Pre-chat information can help direct chat requests more efficiently and reduce the time agents spend collecting the information themselves to resolve the cases.

Understand Pre Chat API 

Use the Pre-Chat API to search for or create customer records automatically when a customer completes a pre-chat form. Here is the list of methods that you can use in pre-chat API
      Searches for or creates records that contain the customer data that’s specified in the pre-chat form that the customer completes. You can call the method as many times as necessary to find the appropriate records. You can list multiple fields and their corresponding details to map the detail values to the appropriate fields within the record as shown below .Here is maps the contact first name and last name with pre-chat form first name and last name.

Use the method to specify which fields to search against existing customer records when a customer completes a pre-chat form.Here is the code that searches the contact based on the pre-chat form email.

Specifies which fields in your method require an exact field value match when you search for existing records.

Use the method to specify which fields in method to use to create a new record if an existing record isn’t found. Specifies which fields in your method to use to create a new record if an existing record isn’t found. You can specify one or more fields for creating new records.


Use the findOrCreate.saveToTranscript method to find or create a record and save it to the chat transcript associated with the chatSaves the record that you found or created using the or
Pre-Chat API methods to the chat transcript associated with the chat when the chat ends.



Use the findOrCreate.showOnCreate method to find or create a record and automatically open it in a subtab in the Salesforce console.Opens the record you created using the and Pre-Chat API methods automatically in a subtab in the to the Salesforce console.


Links the record you’ve found or created using the and methods to another record of a different record type that you created using a separate API call. For example,
you can link a case record you found within your organization to a contact record you create. The findOrCreate.linkToEntity method can’t be used to populate fields on records that you create by using the findOrCreate API call. Instead, use the method to update field values on records.


Here is the complete visualforce page. Go to developer edition and create a new visualforce page with the below code.

Update Chat Buttons and Automated Invitations

Update the live agent chat buttons with the visualforce page that you created above as shown below.

Now if you launch the chat from the site you can able to pre-chat form that will pop up before starting the chat.

Here is result agent can see before accepting the chat.

Based on your the above pre-chat form configuration once the agent is accepting the chat salesforce is going to do the bunch of operations like searching the contacts and opening a new record creating the page and suggest the knowledge article and save it to chat transactions and etc.


Salesforce Live Agent Custom Chat Window

This is simple live agent custom chat window using the visualforce. Create a new visualforce page with below code.

Add it the Chat buttons and automated invitation as shown below.

You can see the chat window as shown below






Live Agent post chat page

Live agent post chat page allows you to share the details with customers at the end of a chat session. For example, you can direct your customers to another
Web page after they complete a chat with an agent, or forward them to a survey about their chat experience. You can create a Visualforce page to host your post-chat page, or you can develop a page on your own and add the URL to your chat
button configuration.

Now go and update the chat button and automated invitations”post chat page ” as shown below with the visual force page your created.

Once chat is ended which will display the result as shown below.insted of showing the simple chat details even you can build your own logic like sending automatic post chat surveys or feedback etc by using post chat pages.