How to Create Surveys Using Flows in Salesforce?

In Salesforce, surveys are feedback or review forms that collect feedback from customers, users, and employees by having them fill out the survey form.

The collected data is stored for further analysis and to improve products, services, and operations.

The Survey feature is available in both Salesforce Lightning and Classic editions. For the developer org, Salesforce offers a survey that includes 300 responses. After extending the limit, we need to go for the paid options.

In this Salesforce tutorial, I will explain how you can automate creating and sending surveys in Salesforce using Flows. With this approach, you can send multiple surveys to users without worrying about survey limitations.

Create a Survey Using Flow in Salesforce

The flow we will create will function similarly to the standard Salesforce survey, displaying various input fields, and the user will receive an email upon successful submission.

For the custom survey management system, we will fulfill the following requirements.

  • A custom object that will store the survey responses.
  • A Lightning Email Template.
  • An email alert will be sent to the user after submission.
  • A screen flow that allows users to give input in the survey fields.
  • A lightning app to render the lightning runtime for flow in a visualforce page.
  • A visualforce page with embedded screen flow.

Create a Custom Object to Store Survey Responses

The first step is to create a custom object with custom fields to store the responses from the Survey inputs. To do so, navigate to the Lightning Setup page and follow the steps below.

  1. On the setup page, click on the Object Manager tab. Click the Create New button to create the custom object. Enter the required fields to create a custom object, Survey Responses.
    • In this custom object, I have included the following custom fields: Comment_C, Email_C, Name_C, and Rating_C.
Custom Survey object in Salesforce

After creating the custom object, ensure that it is in Deployed status.

Email Template for Thank You Email

Now, we will create an Email template for the email sent to the user after successfully submitting the survey.

To create a lightning email template, navigate to the setup and follow the steps below.

  1. On the setup page, click the app launcher, then search and select Lightning Email Template. Then, click on the New Email template button in the next window.
    • Enter the Email Template Name, and in the related entity, select the custom object we created to store survey responses. After this, select the Public Email Templates folder to store the email template.
Salesforce Lightning Survey email template
  1. Enter the subject and email body, then save the email template. Here, I have used {{{Survey_Response__c.Name__c}}}, to autofill the user name to whom the email will be sent.
Send survey to users via flow in Salesforce

Create an Email Alert in Salesforce

In this part, we will create an Email alert using the email template we created in the previous steps.

  1. On the setup page, go to the Quick Find box, then search and select “Email Alerts.” In the Email alerts setup, click New Email alert.
    • Enter the description, and the unique name will be auto-filled. Then, in the Object, select the custom object we created, and in the field, select the email template we created in the previous section.

After this, select the recipients and click on the Save button.

Email alert for Surveys in Salesforce

Create the Screen Flow In Salesforce

Now, we will create a screen flow that will take input from users, store the survey data in the custom object Survey Responses, and send an email to the user after they submit the survey.

To create the screen flow, follow the steps below.

  1. On the Salesforce Lightning setup page, navigate to Quick Find, search, and then select Flows.
    • Click on the New Flow button in the Flows Setup window.
    • In this step, select the Screen flow” option and click “Next.”

Adding Screen Component:

We will use the Screen element to collect the user’s response. Now drag and drop the screen element to the flow canvas.

  1. To take the inputs, we must drag and drop components such as email, name, and Long text fields to accept input for comments.
    • After this, you must also enter the Label and API name for the component.
Create a Survey form using screen flow in Salesforce
  1. Here, I have a picklist field rating (1-10) and added the Picklist component to the screen region.
    • In the screen flow, when we add a picklist, we must define a resource for the picklist. To do this, scroll down to the Choice field and select ‘New Choice Resource‘.
Create surveys using flow in Salesforce
  1. Now, define the new choice resource as follows.
Send Custom survey using flow in Salesforce

Similarly, I have added radio buttons to the screen flow.

  1. Finally, enter the Label and the API Name for the flow, and then click Done.
Salesforce Custom Surveys

With this, the screen component configuration will be completed.

Add Create Record Element

After taking the input from the user through the screen component, we will store the survey responses in the Survey Response custom object. For that, we will add a Create record element to the flow and configure it as follows:

  1. Add the Create Record element to the flow and enter the Label, and the API Name will be auto-filled. Then, select “Manually” in the “How to set record field values” field.
    • After this, select the custom survey object from the Object field.
Salesforce send surveys using flow
  1. Now, map the custom object fields to the screen components fields in the section Set Field Values for the Survey Response (custom object) in the following way.
Save input from custom survey using flow in Salesforce
FieldValue
Comment Survey Form > Comment
EmailSurvey Form > Email
Name{!Name.firstName}{!Name.lastName}
RatingSurvey Form > Survey rating
GenderSurvey Form > Gender

In the mapping, the “Survey form” is the label for the screen component. We have mapped all values as “Survey form> Field value,” but for the Name field, I have manually entered a value {!Name.firstName}{!Name.lastName}.

When we display the Name component on screen, it shows both the first name and last name. However, in the survey object, I only had the name, so I need to map both the first name and last name to the object’s Name field.

Call an Action to Send Email Alert to the User.

In this section, we will add an action element to the flow so that the user receives an email after form submission. In this, we will call the email alertSurvey Thank you Email” created in the above steps.

  1. Add the Action element to the Screen flow.
Send email in Salesforce Surveys using flows
  1. In the action, search and select the Thank you email alert action.
Create custom surveys using flow in Salesforce
  1. After this, enter the Label for the Action component, and the API Name will be auto-filled.
    • In the field Record ID from section, Set Input Values for the Selected Action, select {!User_Response} as value. It will take the response ID from the Create record component.
Email Alert for Custom Surveys in Salesforce
  1. Finally, save the screen flow by clicking Save and then activating the Screen Flow.
    • After completing the screen flow, it is better to test the flow before activation. To test the screen flow, there is an option to debug the flow in the Salesforce flow builder.

Creating a Lightning App to Host Lightning Flow on a Visualforce Page

In this section, we will create a Lightning application that will declare the dependency on the “Lightning:Flow” component.

To create the Lightning app, navigate to the Salesforce developer console and follow the steps below.

  1. In the developer console, select File > New > Lightning Application.
    • Enter the Name for the Lightning app and select the checkbox Lightning Out dependency app, then click on the Submit button.
    • In this, I have named the Lightning app “LightningSurveyApp.”
Create Custom surveys in Salesforce Lightning
  1. Enter the code below to declare a dependency on the Lightning: flow component.
<aura:application access="global" 
                  extends="ltng:outApp"
                  implements="ltng:allowGuestAccess">
    <aura:dependency resource="lightning:flow"/>
</aura:application>

By using implements =: “ltng:allowGuestAccess” it will give access to the guest users.

After entering the above code, save it.

Create a Visualforce Page in Salesforce

Now, we will create a visualforce page with the embedded Lightning flow.

In this visualforce page, we will add the Lightning components for the Visualforce JavaScript library using the <apex:includeLightning/> component.

  1. To create a Visualforce page, select File > New > Visualforce Page in the Developer Console.
    • Enter the code below in the visualforce page and save it.
<apex:page showheader="false" lightningStylesheets="true">
<html>
      <head>
         <apex:includeLightning /> 
      </head>
      <body class="slds-scope">
         <div id="flowContainer" />
         <script>
            var statusChange = function (event) {
               if(event.getParam("status") === "FINISHED") {
                  var outputVariables = event.getParam("outputVariables");
                  var key;
                  for(key in outputVariables) {
                     if(outputVariables[key].name === "myOutput") {
                     }
                  }
               }
            };
            $Lightning.use("c:LightningSurveyApp", function() {
               $Lightning.createComponent("lightning:flow", {"onstatuschange":statusChange},
                  "flowContainer",
                  function (component) {
                     component.startFlow("Survey", );
                  }
               );
            });
         </script>
      </body>
   </html>
</apex:page>
  1. Save the Visualforce code and navigate to the Visualforce page setup from Setup > Quick Find > Visualforce pages.
    • In the Visualforce page setup, select the checkboxes for “Available for Lightning Experience,” “Experience Builder sites,” and the mobile app.
How to create surveys using flow in Salesforce

Deploying the Survey Flow Internally on Applications

In the above steps, we have embedded the screen flow in the Visualforce page. To display that survey in any custom or standard application, follow the steps below.

  1. Open the Application or record page where you want to deploy the Survey, and for that, click on the settings icon and select Edit Page.
    • As we click on the Edit page, the app page will open in the Salesforce Lightning App builder. Here, go to the Components section on the left-hand side, then drag and drop the Visualforce component to the page region.
Add a custom survey in Salesforce visualforce page
  1. After this, select the Visualforce page that we created in the previous steps.
Add custom survey in Salesforce applications
  1. At last, click on the Save button.

Test the flow in internal application:

After deploying the survey visualforce page on the application, we will check it’s working.

  1. Navigate to the application where you have deployed the visualforce page, and there, in the survey form, enter all the required details and click on the Submit or Save button.
Use Screen flow to create Surveys in Salesforce
  1. According to the defined conditions, the email should be sent to the email address we entered into the survey form.
    • In this example, I have entered my email for testing, so I will show you the thank-you email from my inbox.
Send Email for custom survey in Salesforce

Also, the data the user submitted in the survey form should be stored as a record in the Survey Response custom object.

To view the records, navigate to the list of custom objects, and there, you will see the records created after submitting the survey form.

Save custom survey data in Salesforce

This way, we can create and deploy custom surveys in Salesforce using flows.

Create a Force.com Site to Open Flow for Unauthenticated Access

To make the flow accessible to users outside the organization or to those without authentication, we will deploy the flow on a site link from which it can be accessed.

Now, navigate to the setup page of Salesforce Lightning and follow the steps below.

  1. On the setup page, go to the quick find and search, then select sites under Domains and Sites.
    • In the site setup, you need to register the company domain if you haven’t already. After this, click New in the section Sites(company domain name).
How to make a custom surveys accessible to guest users in Salesforce
  1. In the next window, enter all the required details, such as Site Label and Site Name. In the default web address, enter the form name in the input block.
    • On the Active Site Home page, select the Visualforce page that we created. Then, in the Clickjack Protection Level, select ‘Allow Framing by the same origin’.

After configuring the site, click on the Save button.

Deploy custom survey on unauthenticated access in Salesforce
  1. Now, the site link, where we have hosted the Visualforce page with an embedded survey form, will be visible in the Site section of the Sites setup.
    • When you click on the site link, it will open outside the Salesforce environment. This link will be shared with unauthenticated users to allow them to submit the survey.
Salesforce Lightning Custom Survey forms

Common Errors:

If you encounter any errors, such as insufficient permissions, ensure that the guest user profile has permission to create and view the custom object.

  1. To give access to the guest user, click on the site name, and in the next window, click Public Access Settings.
Make custom survey available to guest users in Salesforce
  1. In the user profile settings, scroll down to the section Custom object Permissions, select the checkboxes Read and Create for the custom survey object, and click Save.
Salesforce Custom Survey forms for guest users

If the custom survey form is still inaccessible from the link, then ensure the guest user profiles have access to the flow we created and the visualforce page in which we have embedded the flow.

To check the flow permission, edit the Enabled flow access and Enabled Visualforce Access settings in the user profile and make it available to the user.

Conclusion

In this Salesforce tutorial, we have learned to create a custom Salesforce Survey using the screen flow. This custom survey won’t rely on any configuration of a standard Survey object, and with this, you can send customized surveys to users without worrying about the limitations.

In this process, we created a custom screen flow that will take user input and send an email to the user on a successful form submission. Then, we created a Lightning app with a visualforce page and hosted the screen flow on the Visual Force page.

Finally, I explained how we can make this survey available on internal and external applications by creating a custom site and hosting flow for guests and unauthenticated users.

You may also like to read:


Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.