Survey Responses

Use API responses to show survey questions in Salesforce.

Create a submit button or enable a trigger to call the Apex class for submitting the responses.

The SurveyApi Apex class uses the PATCH request endpoint to submit the survey responses using this format:

Resource 

1/services/data/vXX.X/connect/surveys/<surveyId>/invitation/<invitationId>/survey-response

The invitationId property is retrieved from the POST API request. The flowInterviewState property is retrieved from the first POST API request and later from subsequent PATCH API requests.

Note

Request body for PATCH 

Here’s an example for multiple questions.

1{
2  "invitationId": "0Kixx0000004DbMCAU",
3  "flowInterviewState": "<FlowInterviewState>",
4  "surveyPageResponses": {
5    "questionResponses": [
6      {
7        "name": "q_d217f330_05a6_4e2b_859b_1f1ef210bf84",
8        "questionType": "NPS",
9        "responseValue": 5
10      },
11      {
12        "name": "q_ab781617_3665_4a41_b4ff_f236d73ecb30",
13        "questionType": "FreeText",
14        "responseValue": "Free Text Question Response"
15      },
16      {
17        "name": "q_b1cdfe4c_9c7d_4c2f_ad9d_1915d301d780",
18        "questionType": "ShortText",
19        "responseValue": "Short Text Question Response"
20      },
21      {
22        "name": "q_f84a6a3c_683c_4ed5_864e_5b486baed308",
23        "questionType": "Boolean",
24        "responses": [
25          {
26            "name": "choice1"
27          }
28        ]
29      },
30      {
31        "name": "q_113419b1_5d29_4bb9_8b10_e3fe324ae040",
32        "questionType": "MultiChoice",
33        "responses": [
34          {
35            "name": "c_9775c2e5_9086_44a8_a5c9_89fdc886c99a"
36          },
37          {
38            "name": "c_0f1f63cc_608a_4560_9d29_72b203f195f2"
39          }
40        ]
41      },
42      {
43        "name": "q_1d8690a9_ae95_4e7c_86be_b8057205facc",
44        "questionType": "RadioButton",
45        "responses": [
46          {
47            "name": "c_4867edc8_e9a6_4e86_9fea_b80758e90caf"
48          }
49        ]
50      },
51      {
52        "name": "q_8946f212_25ff_43a8_a507_d267637eee1f",
53        "questionType": "Rating",
54        "responses": [
55          {
56            "name": "c_f51c509a_9643_4a05_89f1_42464de618a6"
57          }
58        ]
59      }
60    ]
61  }
62}

Response 

1{
2   "errors":[],
3   "status":"Success",
4   "surveyPage":{
5     "label": null,
6     "messageDescription":"",
7     "name": null,
8     "redirectUrl": “<URL of the page to be redirected>”,
9     "thankYouMessage":"<Thank you message to be displayed>",
10     "urlButtons":[ // List of URL text and URL for buttons to be displayed
11]
12   }
13}

If the PATCH API request is successful, the feedback is submitted and a Thank You page is displayed.