# 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.feathery.io/platform/build-forms/advanced-logic/examples/api-connectors/pre-fill-form-from-salesforce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
