Skip to content

Instantly share code, notes, and snippets.

@RockyMtnMarc
Last active June 2, 2020 00:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RockyMtnMarc/303cb1f17c6cc9e019cf9458f6b13571 to your computer and use it in GitHub Desktop.
Save RockyMtnMarc/303cb1f17c6cc9e019cf9458f6b13571 to your computer and use it in GitHub Desktop.
//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;
update thisSurveyInvitation[0];
} catch (DmlException e) {
system.debug('Case update error: ' + e);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment