Skip to main content
All CollectionsIntegrationsSalesforce
Add a Simplesat survey to Salesforce Chat
Add a Simplesat survey to Salesforce Chat
Jos Barteling avatar
Written by Jos Barteling
Updated over a week ago

Simplesat allows you to create a CSAT or NPS survey that you can embed directly in Salesforce Chat.

In this article:

Note: We're assuming that you already have Salesforce Chat set up. But if you don't, then click here to learn more about Salesforce Chat.


Create a Simplesat survey

First, create a new survey.

Customize the survey settings to your heart's desires. 😁 Then, choose the Integrate with another tool option in the Publish tab.

Select Salesforce Chat in the pop-up box.

Click the Generate Embed Code button. Make sure you're on the link option, then click Copy survey.


Set up a site

If you already have a site set up, then you can skip this and go to create visualforce page and apex class.

You can check this by going to setup > user interface > sites and domains > sites

Get started by turning on digital experiences.

Note: Once you enable digital experiences, you can't turn it off.

  1. Click the setup gear

    Setup icon

    and select Service Setup.

  2. Enter Experiences in Quick Find, then select Settings under Digital Experiences.

  3. Select Enable Digital Experiences.
    Note: If enhanced domains are enabled in your org, your digital experiences domain is shown. It includes your My Domain name in the format MyDomainName.my.site.com for production orgs.
    ​
    If digital experiences is already enabled for your org, skip steps 4-6.
    ​

  4. Enter a unique value to be used as your domain name and click Check Availability.
    Note: Keep in mind that you can't change the domain name after you save it. You have to call Salesforce to change it.

  5. Click Save.

  6. Click OK.

You should have been redirected to the All Sites page in Setup, but if not, enter All Sites in Quick Find, then select All Sites.

  1. Click New.

  2. Select the Customer Service template.

  3. Click Get Started.

  4. Give a name to your site.

  5. Click Create.

Now you have a site!


Create visualforce page and apex class

First, go to setup > apex classes.

Click new and copy/paste this code in there.

public class PostChatController {

public Case relatedCase { get; set; }

public Contact relatedContact { get; set; }

public Account relatedAccount { get; set; }

public User relatedAgent { get; set; }

public PostChatController() {

String attachedRecords = ApexPages.currentPage().getParameters().get('attachedRecords');

Map<String, Object> recordsMap = (Map<String, Object>) JSON.deserializeUntyped(attachedRecords);

String caseId = (String) recordsMap.get('CaseId');

String contactId = (String) recordsMap.get('ContactId');

String chatDetails = ApexPages.currentPage().getParameters().get('chatDetails');

Map<String, Object> chatDetailsMap = (Map<String, Object>) JSON.deserializeUntyped(chatDetails);

Map<String, Object> agentMap = (Map<String, Object>) chatDetailsMap.get('agent');

String userId = (String) agentMap.get('userId');

if (caseId != null) {

List<Case> cases = [SELECT Id, CaseNumber, Subject FROM Case WHERE Id = :caseId LIMIT 1];

relatedCase = cases.size() > 0 ? cases[0] : null;

}

if (contactId != null) {

List<Contact> contacts = [SELECT Id, FirstName, LastName, Email FROM Contact WHERE Id = :contactId LIMIT 1];

relatedContact = contacts.size() > 0 ? contacts[0] : null;

}

if (userId != null) {

List<User> agents = [SELECT Id, FirstName, LastName, Email FROM User WHERE Id = :userId LIMIT 1];

relatedAgent = agents.size() > 0 ? agents[0] : null;

}

}

public PageReference redirect() {

relatedContact.Id = relatedContact.Id != null ? relatedContact.Id : '';

relatedContact.Email = relatedContact.Email != null ? relatedContact.Email : '';

relatedContact.FirstName = relatedContact.FirstName != null ? relatedContact.FirstName : '';

relatedContact.LastName = relatedContact.LastName!= null ? relatedContact.LastName : '';

relatedAgent.Id = relatedAgent.Id != null ? relatedAgent.Id : '';

relatedAgent.Email = relatedAgent.Email != null ? relatedAgent.Email : '';

relatedAgent.FirstName = relatedAgent.FirstName != null ? relatedAgent.FirstName : '';

relatedAgent.LastName = relatedAgent.LastName != null ? relatedAgent.LastName : '';

relatedCase.Id = relatedCase.Id != null ? relatedCase.Id : '';

relatedCase.Subject = relatedCase.Subject != null ? relatedCase.Subject : '';

PageReference pageRef = new PageReference('yourURLhere');

pageRef.setRedirect(true);

return pageRef;

}

}

Replace the yourURLhere part with the URL you copied from the create a simplesat survey part of this guide and click save.

Next, we'll have to create a visualforce page. To do this, go to setup > visualforce pages.

Click new and set the label and the name to Simplesat.

Replace the code in the page itself with this code:

<apex:page controller="PostChatController" action="{!redirect}" showHeader="false">
</apex:page>

Click save.


Configure permissions

Go to setup > sites.

Click the name of your site.

Then click public access settings and go to visualforce page access.

Click edit and add simplesat to the enabled visualforce pages.
Then click save.

Next, go to setup > CORS

Click new and add https://api.simplesat.io

Then, go to setup > embedded service deployments.

Click the arrow next to the chat you want to edit and then click view.

Click the edit button next to chat settings, then edit additional branding and set the height to 620px minimum and click finish.

Setting the height any lower will not display the survey properly, setting the height higher is fine.

Finally, in the same page enable pre-chat page. Select service and add contact name and email, and case subject.

This will set up a form to ask for a name, email and subject before every chat. This is then used to create a contact and a case in Salesforce.


Adding the survey to the chat

Go to setup > chat buttons & invitations and open your chat button.

Click edit and then at post-chat page select Simplesat.

Click save and you're done!

Did this answer your question?