---
schema_version: "1"
id: b339cf302d2ee18328d6ef75ff846b6176e868d8ba9bc51f1c58f4a2f50fe604
title: SurveyInvitationLinkShortener Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_interface_sfdc_surveys_SurveyInvitationLinkShortener.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_sfdc_surveys_SurveyInvitationLinkShortener.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 329106c2f9b52cce591403de1323d79ed09c0b52e1f42f5e3701f750ce2ad690
description: Use this interface to provide a class factory that Salesforce can call to create instances of your custom SurveyInvitationLinkShortener.Returns a shortened URL for a given survey invitation.
---
# SurveyInvitationLinkShortener Interface

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

## Namespace

[sfdc\_surveys](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_sfdc_surveys.htm "The sfdc_surveys namespace provides an interface for shortening survey invitations.")

## 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_sfdc_surveys_SurveyInvitationLinkShortener.htm#apex_sfdc_surveys_SurveyInvitationLinkShortener_methods)**
- **[SurveyInvitationLinkShortener Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_sfdc_surveys_SurveyInvitationLinkShortener.htm#apex_interface_sfdc_surveys_SurveyInvitationLinkShortener_Example)**

## SurveyInvitationLinkShortener Methods

The following are methods for SurveyInvitationLinkShortener.

- **[getShortenedURL(var1)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_sfdc_surveys_SurveyInvitationLinkShortener.htm#apex_sfdc_surveys_SurveyInvitationLinkShortener_getShortenedURL)**  
    Returns a shortened URL for a given survey invitation.

### getShortenedURL(var1)

Returns a shortened URL for a given survey invitation.

#### Signature

public String getShortenedURL(String var1)

#### Parameters

- **var1**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_methods_system_string.htm)

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_methods_system_string.htm)

## 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](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_callouts_named_credentials.htm "HTML (New Window)").

public with sharing class SurveyInvitationLinkShortenerImpl implements sfdc\_surveys.SurveyInvitationLinkShortener {
   public String getShortenedURL(String invitationURL) {
      return shortenUrlUsingBitlyService(invitationURL);
   }
   public String shortenUrlUsingBitlyService(String invitationURL) {
      HttpRequest request = new HttpRequest();
      request.setEndpoint('callout:bitly/v4/shorten');
      request.setMethod('POST');
      request.setHeader('Authorization', 'Bearer {!$Credential.Password}');
      request.setHeader('Accept', 'application/json');
      request.setHeader('Content-Type', 'application/json');
      request.setBody(JSON.serialize(new Map<String, Object\>{
      'group\_guid' => '{!$Credential.UserName}',
      'long\_url' => invitationURL
      }));
      
      Http http = new Http();
      HttpResponse res = http.send(request);
      
      Object result = JSON.deserializeUntyped(res.getBody());
      if (result instanceof Map<String, Object\>) {
         Map<String, Object\> resultMap = (Map<String, Object\>) result;
         Object shortenedLinkVal = resultMap.get('link');
         if(shortenedLinkVal != null && shortenedLinkVal instanceof String) {
            return (String) shortenedLinkVal;
         }
      }
      return invitationURL;
   }
}