# Pre-fill form from Salesforce

## Overview

This rule runs after a user email is collected on `Step 1` and the step is submitted. The email is used to query a Salesforce instance to fetch other information about the user to prefill onto `Step 2`.

This pattern can be used to look up any Salesforce standard or custom objects based on any field or combination of fields (email, Salesforce ID, etc.)

## Rule Logic

```
// Get user's entered email
const email = salesforceEmail.value;

const query = `SELECT Id, Name, AccountId FROM Contact WHERE Email='${email}' LIMIT 1`;
const API_ENDPOINT = `https://feathery2-dev-ed.develop.my.salesforce.com/services/data/v50.0`;

// Issue request to Salesforce to fetch contact data
const data = await feathery.http.GET(`${API_ENDPOINT}/query?q=${encodeURIComponent(query)}`);
const record = data.records[0];

// Update Feathery fields with data pulled from Salesforce
salesforceName.value = record.Name;
salesforceAccount.value = record.AccountId;
```

## API Connector

Under the API connectors tab, create a connector with the following configuration:

* Base URL: <https://feathery2-dev-ed.develop.my.salesforce.com/services/data/v50.0>
* Allowed Endpoints: `/query`
* Headers:
  * `Authorization`: `Bearer {{salesforce_token}}`

Feathery will automatically detect and populate your Salesforce token in the header when you have Salesforce turned on in the `Integrations` tab.

## Demo

{% embed url="<https://www.loom.com/share/af79e50cb849472795598906efe27566?sid=7f9e11f0-a80d-4870-8080-39a7527a17bc>" %}
