# Connecting to Salesforce (Advanced)

This article covers how to connect the Contact Form app built in the earlier sections to Salesforce, making it possible to save or update users’ information as a Salesforce Contact through the application.

**Prerequisite**

You will need to have a Salesforce account or developer instance in order to create a Salesforce integration in Airkit. To sign up for a salesforce developer account, go to [https://developer.salesforce.com/signup](https://developer.salesforce.com/signup).

You will also need access to the Contact Form described in the previous article.

![01.png](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-c3158497a09f87e417023b0793c9242650bab7fd%2Fconnecting-to-salesforce-v1715-0.png?alt=media)

### Adding a CSAT modal to your Contact Form

Here you will initiate a CSAT (customer satisfaction) modal to pop up once the user enters in their information and clicks on the "Submit" button.

The CSAT modal will be added from [KitCloud](../../building-apps/kitcloud).&#x20;

1. In Web Builder, click on the '+' icon next to Web Flows to open KitCloud and select the CSAT template from the Customer Experience options.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-3782b2ead38a67bb10b034845a89271c688673fa%2Fconnecting-to-salesforce-v1715-1.png?alt=media)

2. Now that the CSAT template is added as a new Web Flow, select the type of CSAT you want to keep. In this example, the CSAT with square edges will be used:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-9d28318489ec361a00ee7d6e344837a7dedef496%2Fconnecting-to-salesforce-v1715-2.png?alt=media)

The other two options can be deleted:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-9983160214cf85a56fb807b00d13b36bb0fe12a3%2Fconnecting-to-salesforce-v1715-3.png?alt=media)

### Triggering the Modal from the Contact Form Web Flow

1. In Web Builder, go to the “Submit” button in the Contact Info Web Page.
2. In the Inspector section, click on Actions. You will see the Navigate to Web Flow Action leading users to the Thank You page after submitting the form.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-a4323fc05dcd57950a2554249893641b72a6c1c7%2Fconnecting-to-salesforce-v1715-4.png?alt=media)

3. Now, click on the '+'  icon and add the Open Modal Action from the Web options. A Modal allows Web Flows to behave like popups.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-3e70fe5b5a6e095c159d1e6ce6fc5801e9fb2dfc%2Fconnecting-to-salesforce-v1715-5.png?alt=media)

4. Select the CSAT Web Flow.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-d0acf1930e20351aacf673998563706b58e78adb%2Fconnecting-to-salesforce-v1715-6.png?alt=media)

### Integrating Salesforce to your application

Integrations are how external systems connect within Airkit. You’ll start configuring the integration in the Console and then continue in the Studio.

#### In the Console

1. Go to Integrations. Click on **Create new**, type a name and select the Salesforce integration. Then click on **Create**.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-606e3bb4d79bb9eac95cbb81c7cac59459283b8c%2Fconnecting-to-salesforce-v1715-7.png?alt=media)

If you are not logged into your Salesforce instance, a popup will display asking you to enter your credentials.

#### In the Studio

1. Access your Contact Form app and go to Configuration Builder. This is where you connect your resources to Airkit. Scroll down to Integrations and click on **New**. Then select **Salesforce** from the **Adapters**.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-51c5d40d71a5fb4e4a4c66408eea359b58cfc651%2Fconnecting-to-salesforce-v1715-8.png?alt=media)

2. In Connected Account, select from the dropdown the one you have just created in the Console.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-e3fb088d77444d4626a1367d95b2693f022f550a%2Fconnecting-to-salesforce-v1715-9.png?alt=media)

3. Save the app.

### Adding a Data Operation to connect to Salesforce

This section will go over the Salesforce Data Operation.

1. First, go to Connection Builder.
2. In Connection Builder, you will see the “Insert Content” Data Flow that was added when the Contact Form was built in the previous section. Add the Salesforce data operation to it by clicking on the '+' icon. Search for Salesforce and select it.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-f09a9fbba490623bc8f4b5d38324f756557fdcf2%2Fconnecting-to-salesforce-v1715-10.png?alt=media)

3. In **Datasource**, select "Salesforce", which is the name of the integration previously created, and under **Operation**, select the type of action you want to perform. In this case, it’s going to be the creation of a new record.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-570d9ee4d0e42373509acd1b551756066428a422%2Fconnecting-to-salesforce-v1715-11.png?alt=media)

4. In\*\* Object Type\*\*, select **Contact**. The Object Body displays the properties you need to create a Contact Object. In this case it requires a Last Name, so the `name` Variable in your Contact Form needs to be passed here. Add the other fields one by one: `phone`, `email` and `company`.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-1010fc681623219ee6c2279203513c3fe92ff5a1%2Fconnecting-to-salesforce-v1715-12.png?alt=media)

5. You can do a quick test within this Data Operation by clicking on **Run**:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-b8f9619d8a1275cc5a081a01f1cda628932d3853%2Fconnecting-to-salesforce-v1715-13.png?alt=media)

The record should be created in Salesforce. Take note of the "id" property&#x20;

### Adding the Transform Data Operation to parse the Salesforce ID

To continue with the Web Flow, after clicking on “Submit”, the CSAT Modal will open for users to select a score. That score will be recorded and then that information will also be passed to the user’s record, thus updating it.

To perform updates, Salesforce requires you to have the ID of the records, which we will be saved as a global variable in the app.&#x20;

1. In Connection Builder, click on the `Salesforce` Variable. This Variable contains the output of the operation that was run.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-891284927a02e8a6cf622584d57b4bd398e32846%2Fconnecting-to-salesforce-v1715-14.png?alt=media)

2. Add a Transform Data Operation to the Data Flow in order to parse the output of the previous operation.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-61027b13448b34890ae37aba22925148be327cba%2Fconnecting-to-salesforce-v1715-15.png?alt=media)

3. In Transform Expression, enter the `Salesforce` Variable and parse through the variable by appending “.result.id” to the end. This way only the ID is shown. Then select Type Text so that you can read the value without the JSON format. Then rename the `Transform` Variable with a more intuitive, like “SalesforceID”.

```javascript
Salesforce.result.id
```

![](https://a01-support.airkit.com/connecting-your-contact-form-to-salesforce/17.png)

4. Finally, select “SalesforceID” as the End Return Value. This will allow you to pass the ID as an output of the Data Flow.

![](https://a01-support.airkit.com/connecting-your-contact-form-to-salesforce/18.png)

### Creating a new Data Flow to update records

This will be used later on to pass the CSAT score and comments associated to update the record in Salesforce. This will be visited when configuring the CSAT Web Flow.

1. In Connection Builder, click on the Create Blank to add a new Data Flow. Rename it to "Update Record".

![](https://a01-support.airkit.com/connecting-your-contact-form-to-salesforce/19.png)

2. As Inputs, create the following three variables of type Text one by one: `Salesforce_id`, `CSAT` and `Feedback`. These variables will allow you to pass in the content from the CSAT Web Flow to this Data Flow.

![](https://a01-support.airkit.com/connecting-your-contact-form-to-salesforce/20.png)

3. Add the Salesforce Data Operation. In **Datasource**, select **Salesforce**. In Operation, this time add Update record.

![](https://a01-support.airkit.com/connecting-your-contact-form-to-salesforce/21.png)

4. In **Object Type**, select **Contact** and then, check the **Custom Expression** box to enter your `Salesforce_id` variable in the required id field. Finally, since this Data Flow was created to add the information on the CSAT Web Flow to the record, in Update Body, select **Contact Description** (this is where the info will be stored in the Salesforce record) and then pass the CSAT and Feedback Variables:

```javascript
CONCAT(CSAT, “-”, Feedback)
```

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-70217a1782b76c1012e76ce39f6c699ff168166b%2Fconnecting-to-salesforce-v1715-16.png?alt=media)

When it comes the turn to configure the Event, this Data Flow will be ready to be used.

### Creating a global variable for the Salesforce ID

By creating a global variable that stores the SalesforceID, you will be able to pass it across Web Flows.

1. Go to Journey Builder and, in the **General** tab of the Inspector section, click on the '+' icon next to Global Variables. Select a Text type and rename it to "salesforce\_id".

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-7bcba2b16c41334351b82f7546da7c3c5aaf3e7d%2Fconnecting-to-salesforce-v1715-17.png?alt=media)

### Connecting the Data Flow to the Web Flow

So that the user’s information can be stored in the `salesforce_id` Variable, you need to connect the Data Flow to the “Submit” button in the Contact Form Web Flow.

1. Go to Web Builder and, in the “Submit” button, add the Run Data Flow action.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-489769dbccb9ed1ae6a21188db5d746d49405661%2Fconnecting-to-salesforce-v1715-18.png?alt=media)

2. Select the “Insert Content” Data Flow and pass the input variables for each of the fields in the form. Finally, in **Output Binding**, enter the recently created global variable:

```javascript
session.salesforce_id
```

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-3e044af2ee2321bebe0cea677f612c64ce79fca9%2Fconnecting-to-salesforce-v1715-19.png?alt=media)

3. Now go to the CSAT Web Flow. In the “Submit feedback” button actions, you will see a pre-configured event. If you click on it, you can see the Inputs that are passing the score and the feedback:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-8b71e0021149640b37fcc8dac8ef667f908290ec%2Fconnecting-to-salesforce-v1715-20.png?alt=media)

4. Go back to Journey Builder and click on the CSAT Selected Event. In the Action Builder, add a new Data Flow. Finally, select the “Update record” Data Flow and as Inputs, select the variables corresponding to the Salesforce ID, CSAT score and Feedback fields.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-3614c7440f78ca9c78d9b434447fea8817b2c36d%2Fconnecting-to-salesforce-v1715-21.png?alt=media)

5. Save the app.

### Previewing the application

Once the app is all set, it can be tested in the App Preview.

1. Click on Preview at the right-hand corner of the Studio, which will open a new tab.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-72804cd545ebd301e898336e4627a5be992f57db%2Fconnecting-to-salesforce-v1715-22.png?alt=media)

2. Click on the globe icon, which allows the app to be launched from the start.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-85f67ec2af1441c5e69de7edc3a441b5b3d9136d%2Fconnecting-to-salesforce-v1715-23.png?alt=media)

3. Complete the fields and click on “Submit”.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-927345ff4870f8cdb48332e66cd775b04aee9298%2Fconnecting-to-salesforce-v1715-24.png?alt=media)

As expected, the CSAT Modal will pop up for the user to select the score and add some feedback.&#x20;

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-c872df181b0cc4f35ca9ba734d6c012214c422a9%2Fconnecting-to-salesforce-v1715-25.png?alt=media)

### Verifying Contact was created in Salesforce and updated with CSAT

1. Sign into your Salesforce account or developer instance, click on the App Launcher icon and select Sales Console.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-2f3f629e2d340c22e2eb7566259d0fb3d0ae7a0e%2Fconnecting-to-salesforce-v1715-26.png?alt=media)

2. Once in the Sales Console, click on the arrow icon and select Contacts.

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-51c59b0466ba31ffdf5072c0e472182c98d6b767%2Fconnecting-to-salesforce-v1715-27.png?alt=media)

3. Identify the user that was created through the Airkit application. The record should be added updated in Salesforce with the CSAT details in the contact description:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-ce2b675f80a5655fd443b4f40ab732ca58998e62%2Fconnecting-to-salesforce-v1715-28.png?alt=media)
