SurveyInvitationLinkShortener Interface

Use this interface to provide a class factory that Salesforce can call to create instances of your custom SurveyInvitationLinkShortener.

Namespace 

sfdc_surveys

Usage 

Implement an instance of the SurveyInvitationLinkShortener interface to shorten the survey invitation that can be distributed as short URLs over customer engaged channels, such as SMS, WhatsApp, or Facebook Messenger.

Special access rules 

To implement this interface, you must have the Salesforce Feedback Management license enabled in your Salesforce organization.

SurveyInvitationLinkShortener Methods 

The following are methods for SurveyInvitationLinkShortener.

getShortenedURL(var1) 

Returns a shortened URL for a given survey invitation.

Signature 

public String getShortenedURL(String var1)

Parameters 

Return Value 

Type: String

SurveyInvitationLinkShortener Example Implementation 

This is an example implementation of the sfdc_surveys.SurveyInvitationLinkShortener interface.

This sample code uses Named Credentials for authentication. For more information on Named Credentials, see Named Credentials as Callout Endpoints.

1public class SurveyInvitationLinkShortenerImpl implements sfdc_surveys.SurveyInvitationLinkShortener {
2   public String getShortenedURL(String invitationURL) {
3      return shortenUrlUsingBitlyService(invitationURL);
4   }
5   public String shortenUrlUsingBitlyService(String invitationURL) {
6      HttpRequest request = new HttpRequest();
7      request.setEndpoint('callout:bitly/v4/shorten');
8      request.setMethod('POST');
9      request.setHeader('Authorization', 'Bearer {!$Credential.Password}');
10      request.setHeader('Accept', 'application/json');
11      request.setHeader('Content-Type', 'application/json');
12      request.setBody(JSON.serialize(new Map<String, Object>{
13      'group_guid' => '{!$Credential.UserName}',
14      'long_url' => invitationURL
15      }));
16      
17      Http http = new Http();
18      HttpResponse res = http.send(request);
19      
20      Object result = JSON.deserializeUntyped(res.getBody());
21      if (result instanceof Map<String, Object>) {
22         Map<String, Object> resultMap = (Map<String, Object>) result;
23         Object shortenedLinkVal = resultMap.get('link');
24         if(shortenedLinkVal != null && shortenedLinkVal instanceof String) {
25            return (String) shortenedLinkVal;
26         }
27      }
28      return invitationURL;
29   }
30}