Use - Case: When you want to send surveys created on SurveySensum via Salesforce, you have to configure this integration.
Flow of Integration -
Event happens in Salesforce, like a ticket gets closed.
Immediately a request is sent to SurveySensum, please return a survey link for the customer who’s ticket is closed
SurveySensum returns a unique survey link, and workflow is triggered in Salesforce to use that link and send the survey to the customer.
Note* - You need to configure a workflow in salesforce that sends an automatic survey to the customer after the ticket gets closed.
In this article we are going to Share a Survey Link via Salesforce Flow and Apex class.
This process involves two steps. These steps involve little technical knowledge, so it is recommended you have a Salesforce Engineer and SurveySensum team to help you through the process. The steps are as follows:
Click on setup and open the developer console.
In Salesforce, add an Apex Class and create an “@invocable method” (The action reads the invocable methods). Like we have created a Class “CampaignController” and added an Invocablemethod “SendCampaign” with a List of emails as a parameter(InvocableMethod only allows List<T>).
public class CampaignController {
@invocablemethod(Label='Send survey' description='Makes API call')
public static void sendCampaign(List<String> email){
String contactEmail = email[0];
if(!System.isFuture() && !System.isBatch()){
GetSurveyLinkCallout.getSurveyLink(contactEmail);
}
}
}
Inside the method, we take the Email as a parameter and call another method. In the above screenshot, you can see we have called the “getSurveyLink” method defined in the “GetSurveyLinkCallout” class.
Now create a new Class that contains your API callout. As mentioned above we have created a class “GetSurveyLinkCallout”, inside the class, we have added a method “getSurveyLink”. We have made the method “@future(callout=true)” as we have to make an HTTP call. In this method, we are updating two custom fields of contacts “Survey Link” and “Survey Link Updated” to “True”.
public class GetSurveyLinkCallout {
@future(callout=true)
public static void getSurveyLink(String contactEmail){
String apiUrl = 'https://open-api.surveysensum.com/api/v2/Share/shareSurvey/link?surveyGuid=c9341fa9-8e3e-4ccc-906f-2a268dab977e';
System.debug(contactEmail);
Http h = new Http();
httpRequest request = new HttpRequest();
request.setMethod('POST');
request.setTimeout(60000);
request.setEndpoint(apiUrl);
String authorizationHeader = 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImEyNTYwZTZmMmYyMjU1NGIzOWM3NTllNGFiOWVmYWIwIiwidHlwIjoiSldUIn0.eyJuYmYiOjE2NzE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cyIsInVwZGF0ZV93ZWJob29rcyIsImRlbGV0ZV93ZWJob29rcyIsInZpZXdfcmVzcG9uc2VzIiwidmlld19lbWFpbF90ZW1wbGF0ZXMiXSwic2NvcGUiOlsib3BlbmlkIiwicHJvZmlsZSIsIm1hbmFnZV9jb250YWN0X2xpc3RzIiwibWFuYWdlX2NvbnRhY3RzIiwibWFuYWdlX3N1cnZleXMiLCJtYW5hZ2Vfd2ViaG9va3MiLCJzdXJ2ZXlfc2hhcmUiLCJ2aWV3X2NvbnRhY3RfbGlzdHMiLCJ2aWV3X2NvbnRhY3RzIiwidmlld19lbWFpbF90ZW1wbGF0ZXMiLCJ2aWV3X3Jlc3BvbnNlcyIsInZpZXdfc3VydmV5cyIsInZpZXdfd2ViaG9va3MiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicHdkIl19.2YpckkxBhUJF612GxNQ6h5NS6IPeH2z7hDTfbl8elDaX3dfdkg1l4gDWPwv0C_7kXyggixE1vf-VMr_VftcE8VBbguz8NDLW5g5JZp_cJ4acC7pmU3vaaJQ1fSXYWipvDLtXWo1tGijAoK3cKHr6mRum-SWZlNmtIwomiwmuOeuLQA0OFvCHHOnDLJu2piuxtNUZXnQkTpeey1q9VLMKr1yCDofOLJWXUIxCs6rrvF4hm0AnRd1zZtDDHFt2zS8bRlJ1YP-IYQOLgo03Pu3QbJGn9tizWfHqxsDWVL-3ZbbddhYCnpsfF_i8m9AkZMJzEQkmwJcXd8muQaA4dwHUuQ';
request.setHeader('Authorization', authorizationHeader);
String requestBody = '{"contactInfo": [{"key": "vz_c_name","value": "Aashish"},{"key": "vz_c_email","value": "'+ contactEmail +'"}],"metadata": [{"key": "vz_transaction_id","value": "T-4"}]}';
System.debug(requestBody);
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody(requestbody);
HttpResponse response = h.send(request);
String respData = response.getBody();
system.debug('Response ' + respData);
if (response.getStatusCode() == 200)
{
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> surveyLinks = (List<Object>) results.get('result');
System.debug(String.valueof(surveyLinks[0]));
Contact contactInstance = new Contact();
contactInstance = [SELECT Survey_Link__c, Survey_Link_Updated__c From Contact WHERE Email = :contactEmail LIMIT 1];
contactInstance.Survey_Link__c = String.valueof(surveyLinks[0]);
contactInstance.Survey_Link_Updated__c = 'True';
update contactInstance;
}
}
}
Add a record trigger, having a condition that checks if the Contact field: “Survey Link Updated“ equals “True”.
Add Update Records data elements to update the “Survey Link Updated” field to “False”.
Add Email Action for Send an email campaign, in the campaign body we can add “Survey Link” field which consists of the latest value of the link.
These steps will allow you to send a Survey Link to any customer using Salesforce and Apex class.