+ Start a Discussion
Mikko MalmariMikko Malmari 

Best way to trigger apex on live agent chat request

I want to build a custom implementation using the Live Agent API, but I've yet to figure out how to get information about a chat request made by a visitor, and to trigger Apex once a request is made. Is this something that can be accomplished with Process builder or Visitor trigger?
jigarshahjigarshah
Mikko,

You could write a before or an after Insert Apex Trigger on the LiveChatTranscript object (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_livechattranscript.htm) to trigger your custom logic. As per the documentation "LiveChatTranscript is automatically created for each Life Agent chat session and stores information about the session. This object is available in API version 24.0 and later."

Your Apex trigger can be as follows.
trigger LiveChatTranscriptTrigger on LiveChatTranscript(after insert) {     

	if(Trigger.isAfter){
	
		if(Trigger.isInsert){
		
			for(LiveChatTranscript chatTranscript :Trigger.new){
			
				//Your custom business logic can be implemented here
			    .
				.
				.
			}
		}
	}//Is After
}
jigarshahjigarshah
These are additional links that you can leverage to get yourself acquainted with Salesforce Live Agent.
  • Trailhead Modules
    • https://trailhead.salesforce.com/en/modules/service_live_agent
    • https://trailhead.salesforce.com/projects/build_branded_chat
  • https://help.salesforce.com/articleView?id=live_agent_transcript_events.htm&type=5
jigarshahjigarshah
Mikko,

Has your issue been addressed? If yes, please close this thread.
Mikko MalmariMikko Malmari
Hello,

Not yet, however I am not sure where the exact issue is. I tried triggering a REST API call to an external url but have not been able to receive the call on the server.