Skip to content

Instantly share code, notes, and snippets.

@RockyMtnMarc
RockyMtnMarc / EinsteinBotsUtility3
Last active September 26, 2019 18:32
Visualforce code example for an Lightning Console Einstein Bots Utility
<apex:page >
<!--BEGIN Chat Button Code Snippet-->
<a id="liveagent_button_online_5733i000000gfJr" href="javascript://Chat" style="display: none;" onclick="liveagent.startChat('5733i000000gfJr')"><!-- Online Chat Content --></a><div id="liveagent_button_offline_5733i000000gfJr" style="display: none;"><!-- Offline Chat Content --></div><script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('5733i000000gfJr', document.getElementById('liveagent_button_online_5733i000000gfJr'));
liveagent.showWhenOffline('5733i000000gfJr', document.getElementById('liveagent_button_offline_5733i000000gfJr'));
});</script>
@RockyMtnMarc
RockyMtnMarc / EinsteinBotsUtility2
Created September 26, 2019 00:25
Visualforce code example for an Lightning Console Einstein Bots Utility
<apex:page >
<!--BEGIN Chat Button Code Snippet-->
<a id="liveagent_button_online_5733i000000gfJr" href="javascript://Chat" style="display: none;" onclick="liveagent.startChat('5733i000000gfJr')"><!-- Online Chat Content --></a><div id="liveagent_button_offline_5733i000000gfJr" style="display: none;"><!-- Offline Chat Content --></div><script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('5733i000000gfJr', document.getElementById('liveagent_button_online_5733i000000gfJr'));
liveagent.showWhenOffline('5733i000000gfJr', document.getElementById('liveagent_button_offline_5733i000000gfJr'));
});</script>
@RockyMtnMarc
RockyMtnMarc / EinsteinBotsUtility1
Last active September 26, 2019 00:56
Visualforce code example for an Lightning Console Einstein Bots Utility
<apex:page>
<!--BEGIN Chat Button Code Snippet-->
<a id="liveagent_button_online_5733i000000gfJr" href="javascript://Chat" style="display: none;" onclick="liveagent.startChat('5733i000000gfJr')"><!-- Online Chat Content --></a><div id="liveagent_button_offline_5733i000000gfJr" style="display: none;"><!-- Offline Chat Content --></div><script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('5733i000000gfJr', document.getElementById('liveagent_button_online_5733i000000gfJr'));
liveagent.showWhenOffline('5733i000000gfJr', document.getElementById('liveagent_button_offline_5733i000000gfJr'));
});</script>
@RockyMtnMarc
RockyMtnMarc / SurveyInvitationURLFormula
Last active September 21, 2019 17:25
Salesforce Process Builder Formula for generating a Survey Invitation URL
'https://YOUR_DOMAIN_HERE.force.com/survey/runtimeApp.app?invitationId='+
[SurveyInvitation].Id+
'&surveyName=YOUR_SURVEY_API_NAME_HERE&UUID='
+[SurveyInvitation].UUID
@RockyMtnMarc
RockyMtnMarc / themeLayoutNoHeader.css
Created August 17, 2019 04:59
Custom Community Theme Layout style sheet for post-chat surveys with no header
.THIS {
position: relative;
z-index: 1;
}
.THIS .surveyRuntimeSurvey.surveyScreen {
min-width: 0;
margin: -13px;
width: calc(100% + 25px) !important;
padding-bottom: 50px !important;
@RockyMtnMarc
RockyMtnMarc / themeLayoutNoHeader.cmp
Created August 17, 2019 04:56
Custom Community Theme Layout for post-chat surveys with no header
<aura:component implements="forceCommunity:themeLayout" access="global" description="Custom Community Theme Layout for post-chat surveys with no header">
<div>
<div class="mainContentArea">
{!v.body}
</div>
</div>
</aura:component>
@RockyMtnMarc
RockyMtnMarc / SurveyRedirectPage.vfp
Created August 17, 2019 04:22
Visualforce Page which redirects the user to the Survey URL.
<apex:page controller="SurveyRedirectController" action="{!redirectToSurvey}" >
</apex:page>
@RockyMtnMarc
RockyMtnMarc / SurveyRedirectController.apxc
Created August 17, 2019 04:17
Apex Class which retrieves the Survey_URL__c field from the LiveChatTranscript with the specified ChatKey
public class SurveyRedirectController {
public PageReference redirectToSurvey() {
String url = [SELECT Id, Survey_URL__c, ChatKey FROM LiveChatTranscript WHERE ChatKey = : ApexPages.currentPage().getParameters().get('chatKey')].Survey_URL__c;
PageReference surveyURL = new PageReference(url);
return surveyURL;
}
}
//This trigger updates the LiveChatTranscript.Survey_URL__c field with a valid SurveyInvitation URL and creates a lookup relationship from the SurveyInvitation.Chat_Transcript__c to the LiveChatTranscript
trigger LiveChatTranscript_CreateSurveyURL on LiveChatTranscript (before update) {
for (LiveChatTranscript lct : Trigger.New){
if(lct.Status == 'Waiting'){
List<SurveyInvitation> thisSurveyInvitation = [SELECT Id, UUID, Name FROM SurveyInvitation WHERE ChatKey__c = :lct.ChatKey LIMIT 1];
//Set the surveyName variable to the API name of your Survey record
lct.Survey_URL__c = 'https://sdodemo-main-166ce2cf6b6-16bd728c779.force.com/consumer/survey/runtimeApp.app?invitationId=' + thisSurveyInvitation[0].Id + '&surveyName=hutch_test&UUID=' + thisSurveyInvitation[0].UUID;
if (thisSurveyInvitation.size() > 0){
try {
thisSurveyInvitation[0].Chat_Transcript__c = lct.Id;
@RockyMtnMarc
RockyMtnMarc / LiveChatTranscript_CreateSurveyInvitation.apxt
Last active November 10, 2021 11:04
Apex Trigger to create a new SurveyInvitation for every new LiveChatTranscript
//This trigger creates a new SurveyInvitaion record for each LiveChatTranscript for use in a post-chat survey
//This trigger assumes that a Contact record has been associated with each LiveChatTranscript, for example using a pre-chat form
trigger LiveChatTranscript_CreateSurveyInvitation on LiveChatTranscript (before insert) {
for (LiveChatTranscript lct : Trigger.New){
if(lct.ContactId != null){
//Change %Consumer% in the following line to a unique keyword for the Community Name where your surveys are published
List<Community> thisCommunity = [SELECT NetworkId FROM Community WHERE Name LIKE '%Consumer%' LIMIT 1];
//Change %Hutch% in the following line to a unique keyword for the Survey you want to show your chat users
List<Survey> thisSurvey = [SELECT Id,Name FROM Survey WHERE Name LIKE '%Hutch%' LIMIT 1];