How to Create Surveys Using Flows in Salesforce? : Abhijeet
by: Abhijeet
blow post content copied from SalesForce FAQs
click here to view original post
**Summary of Creating Surveys in Salesforce Using Flows** In Salesforce, surveys are forms used to gather feedback from customers, users, and employees. This feedback is crucial for improving products and services. Surveys can be created in both Salesforce Lightning and Classic editions, with a limit of 300 responses in the developer org. If more responses are needed, a paid option is required. This tutorial guides you through automating the creation and distribution of surveys using Salesforce Flows. This method allows you to bypass standard survey limitations. ### Key Steps to Create a Survey Using Flow: 1. **Create a Custom Object**: - Create a custom object named "Survey Responses" to store feedback. - Add fields like Comment, Email, Name, and Rating. 2. **Email Template**: - Develop a Lightning Email Template to thank users for their feedback. 3. **Email Alert**: - Set up an email alert using the template created earlier to notify users upon survey submission. 4. **Screen Flow**: - Create a screen flow to collect user input. - Use components like text fields and picklists to gather data. 5. **Create Record Element**: - Store the collected survey data in the custom object. 6. **Send Email Alert**: - Include an action in the flow to send the thank-you email after survey submission. 7. **Lightning App and Visualforce Page**: - Create a Lightning app to host the flow and embed it in a Visualforce page. 8. **Deploy the Survey**: - Add the Visualforce page to an application for internal use or create a Force.com site for external access. 9. **Permissions**: - Ensure guest users have the necessary permissions to access the survey. ### Conclusion: This tutorial demonstrates how to create a custom survey in Salesforce using Flows, allowing for tailored surveys without the constraints of standard survey configurations. Users can submit feedback, and upon submission, they receive a thank-you email, with their responses stored in a custom object. ### Additional Information: Creating surveys in Salesforce can significantly enhance customer engagement and provide valuable insights for business improvements. By leveraging Flows, organizations can automate processes and ensure a seamless experience for users. ### Hashtags for SEO: #Salesforce #Surveys #SalesforceFlows #CustomerFeedback #SalesforceTutorial #Automation #CRM #SalesforceLightning #Visualforce #EmailAlerts #CustomObjects #UserEngagement
In Salesforce, surveys are feedback or review forms that collect feedback from customers, users, and employees by filling out the survey form, and that 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 a number of surveys to users without worrying about survey limitations.
Create a Survey Using Flow in Salesforce
The flow we will create will work similarly to how the standard Salesforce survey works; it will display various input fields, and the user will get an email on 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 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.
2. Click the Create New button to create the custom object.
3. Enter the required fields to create a custom object, Survey Responses.
4. In this custom object, I have included custom fields Comment_C, Email_C, Name_C, and Rating_C.

After creating the custom object, ensure that it is in Deployed status.
Email Template for Thankyou 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 on the app launcher and then search and select Lightning Email Template. Then, click on the New Email template button in the next window.
2. 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.

3. Enter the subject and email body, then save the email template. Here, I have used }, to autofill the user name to whom the email will be sent.

Create an Email Alert
In this part, we will create an Email alert using the email template we created in 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.
2. 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.

Create the Screen Flow
Now, we will create a screen flow that will take input from the users, store the survey data in the custom object Survey Responses, and send an email to the user after submitting the survey.
To create the screen flow, follow the steps below.
1. On the setup page of Salesforce Lightning, go to the quick find and search, then select flows.
2. Click on the New Flow button in the flows setup window.
3. In this step, select the option Screen flow and click Next.
Adding Screen Component:
We will use the Screen element to take the input for the user response.
Now drag and drop the screen element to the flow canvas.
1. To take the inputs, we must drag and drop the components like email, name, and Long text fields to accept input of comments.
After this, you must also enter the Label and API name for the component.

2. 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 have to define a resource for the Picklist, and for that, scroll down to the Choice field and select New Choice Resource.

3. Now, define the new choice resource as follows.

In the same way, I have added radio buttons to the screen flow.
4. At last, enter the Label and the API Name for the flow and click Done.

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 field How to set record field values.
After this, select the custom survey object from the Object field.

2. 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.

Field | Value |
Comment | Survey Form > Comment |
Survey Form > Email | |
Name | {!Name.firstName}{!Name.lastName} |
Rating | Survey Form > Survey rating |
Gender | Survey Form > Gender |
In the mapping, the “Survey form” is the screen component label. We have mapped all values as “Survey form> Field value,” but for the Name field, I have manually entered value {!Name.firstName}{!Name.lastName}.
When we take the Name component on screen, it takes the first name and last name, but in the survey object, I only had the name, so I have to map both the first name and last name with 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 the user will receive an email after the form submission. In this, we will call the email alert “Survey Thank you Email” created in the above steps.
1. Add the Action element to the Screen flow.

2. In the action, search and select the Thank you email alert action.

3. 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.

4. Finally, save the screen flow; click Save and Activate 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.
2. 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 Lighting app as LightningSurveyApp.

3. 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
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 the visualforce page, select File > New > Visualforce Page in the developer console.
2. Enter the below code 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>
3. Save the visualforce code and go to the visualforce page setup from Setup > Quick Find> Visualforce pages.
In the visualforce page setup, select the checkbox Available for Lightning Experience, Experience Builder sites, and the mobile app.

Deploying the Survey Flow Internally on Applications
In the above steps, we have embedded the screen flow in the Visualforce page, and to display that survey in any of the custom or standard applications, 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.
2. 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.

3. After this, select the visualforce page we created in the above steps.

4. 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.

2. 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.

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.

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 the user outside the org or to users without any authentication, we will deploy the flow on a site link from where 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.
2. 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).

3. In the next window, enter all the required details, such as Site Label, Site Name. In the default web address, enter the form name in the input block.
In the Active Site Home page, select the visualforce page that we created, and in the Clickjack Protection Level, select Allow Framing by the same origin.
After configuring the site, click on the Save button.

3. Now, the site link, where we have hosted the visualforce force with embedded survey form, will be visible in the site section on the Sites setup.
When you click on the site link, it will open outside the Salesforce environment, and this link will be shared with the unauthenticated users to submit the survey.

Common Errors:
If you face any error, such as not having enough permissions, then 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.

2. 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.

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:
- What Is Salesforce CRM Analytics (CRMA)?
- Salesforce OmniStudio
- What Is Salesforce Digital Engagement?
- How to Use Salesforce for Project Management?
The post How to Create Surveys Using Flows in Salesforce? appeared first on SalesForce FAQs.
January 20, 2025 at 04:21PM
Click here for more details...
=============================
The original post is available in SalesForce FAQs by Abhijeet
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Post a Comment