> ## Documentation Index
> Fetch the complete documentation index at: https://sequin.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Salesforce Setup

<Warning>
  **Pardon the mess**

  You are viewing docs related to an older version of Sequin. We're in the process of updating our provider-specific guides and will be done in a few weeks (May 2024). [Please click here](/docs/) to view the latest version of the docs.

  If you're interested in Salesforce and want to learn more about what's changing, [send us a note](mailto:support@sequin.io).
</Warning>

**In 2 minutes, you will sync all your Salesforce data to a Postgres database and can begin building on it with SQL or your favorite ORM.**

This guide walks you through setting up a real-time sync between Salesforce and your database using Sequin.

In just a couple of minutes, you'll initialize your sync, query your Salesforce data, and complete your integration by updating a Salesforce contact using the Sequin Proxy.

<Note>You'll need to ensure that you have access to a Salesforce user with permissions to access the Salesforce API.</Note>

## Create a Salesforce sync[](#create-a-salesforce-sync "Direct link to Create a Salesforce sync")

Connect Salesforce and your database to Sequin to start your sync.

<img src="https://mintcdn.com/sequin/3H0rKJAg0ey1fqux/images/001_salesforce.png?fit=max&auto=format&n=3H0rKJAg0ey1fqux&q=85&s=547078c5cafbca74f987a06b42582ad8" alt="Connect Salesforce to Postgres with Sequin" width="997" height="666" data-path="images/001_salesforce.png" />

**Step 1:** If you don't have one already, create a new Sequin account at [https://console.sequin.io/signup](https://console.sequin.io/signup).

**Step 2:** Select **Salesforce** as the platform you want to sync.

**Step 3:** Now connect your Salesforce instance to Sequin by selecting **Add new API key**. Enter your Salesforce subdomain. You can find your Salesforce subdomain by logging into the Salesforce instance you want to sync and copying the root of the URL:

<img src="https://mintcdn.com/sequin/3H0rKJAg0ey1fqux/images/002_subdomain.png?fit=max&auto=format&n=3H0rKJAg0ey1fqux&q=85&s=fd9752d0f3c3dbf73eab512a27e304d3" alt="Enter your salesforce subdomain" width="901" height="478" data-path="images/002_subdomain.png" />

Click **Connect to Salesforce** and finish connecting to your Salesforce instance by entering your Salesforce credentials in the authentication modal:

<img src="https://mintcdn.com/sequin/3H0rKJAg0ey1fqux/images/003_salesforce_auth.png?fit=max&auto=format&n=3H0rKJAg0ey1fqux&q=85&s=1be6783d03522ecbb838443496b192aa" alt="Enter your salesforce credentials" width="901" height="635" data-path="images/003_salesforce_auth.png" />

**Step 4:** Select the **Salesforce objects** you want to sync to your database. Sequin syncs standard objects and custom objects to tables in your database.

**Step 5:** By default, Sequin syncs all the standard and custom **fields** of each Salesforce object to columns in your database. You can [choose which fields will sync](/docs/data-mapping#selecting-columns) to your database and [edit the column name for each field](/docs/data-mapping#selecting-columns) by clicking the gear icon.

**Step 6:** Connect to the destination database you want to sync your Salesforce data to. We suggest you sync to a database you host by choosing the **Connect** option and following the steps to [connect to your database](/docs/sync-process/self-hosted). Or, if you want to get up and running quickly, click the **Launch** option to spin up a demo database we host for you (on Amazon RDS).

**Step 7:** Click **Create**.

After you click **Create**, Sequin will begin backfilling all your data. We'll show you the progress we're making in the console. Within a minute or two, you can begin exploring your schema and querying your data in SQL. We'll send you an email when your backfill is complete.

## Query your Salesforce data using SQL[](#query-your-salesforce-data-using-sql "Direct link to Query your Salesforce data using SQL")

Connect to your database via [Sequin's Postgres Proxy](/docs/sql-writes), which lets you write to your synced tables as well as read them. We'll use [psql](https://www.postgresql.org/docs/current/app-psql.html) as an example in this setup guide, but you can use any SQL client that works with Postgres.

**Step 1:** Go to **Connection Instructions** on the Sequin console. Copy the `psql` command to connect to your database via the Proxy.

**Step 2:** Open your terminal, and paste the `psql` command. Press **Enter**. This will open a connection to your database so you can write your first query:

```sql theme={null}
psql -d {your_connection_string_here}
psql (14.2, server 12.11)
Type "help" for help.

dbh2vw0hqmoc9sj=>

```

**Step 3:** To get a sense of your schema, list all the tables you're syncing to your database by typing the command `\dt`:

```sql theme={null}
dbh2vw0hqmoc9sj=> \dt

               List of relations
 Schema |        Name        | Type  |  Owner
--------+--------------------+-------+----------
 public | _sync_cdc          | table | postgres
 public | account            | table | postgres
 public | contact            | table | postgres
 public | lead               | table | postgres
 public | opportunity        | table | postgres
 public | user_              | table | postgres
(6 rows)

```

You'll see all the Salesforce objects you selected when setting up your sync are now tables in your database. You'll also see some `_sync` tables which Sequin uses to manage your sync.

**Step 4**: Write your first query. You can start with a simple `select` to get your bearings:

```sql theme={null}
dbh2vw0hqmoc9sj=> select count(*) from contact;

 count
-------
    15
(1 row)

```

Now, pull the contact `api_id`, `first_name`, and `last_name` for a specific customer to use in the next step:

```sql theme={null}
dbh2vw0hqmoc9sj=> select api_id, first_name, last_name from contact where email = 'eric@sequin.io';
       api_id       | first_name | last_name
--------------------+------------+-----------
 0038V00002ZBQ8pQAH | Eric       | Goldman
(1 row)

```

Great, you can now use this `api_id` in the last step of this setup guide.

## Write back to Salesforce[](#write-back-to-salesforce "Direct link to Write back to Salesforce")

To create, update, or delete objects in Salesforce, you can `insert`, `update`, or `delete` rows in your Postgres database.

When you're connected to your database through the Sequin Proxy, the Proxy listens for changes. When you make a mutation, the Proxy applies the mutation to Salesforce's API first. If the mutation succeeds, your database is updated as well. If it fails, your database mutation will be rolled back, and you'll receive a Postgres error.

In this example, you'll update the `contact` in the prior step by giving them a new first and last name:

```sql theme={null}
update contacts
set firstname = 'Sequin', lastname = 'Setup'
where id = '{{contact_id}}'

```

This call will update the first and last name of that contact. If the Postgres write returned without an error, that means the API write succeeded as well!

You can see over on Salesforce that the record has updated.

**Step 3:** Now, confirm the change in your database. Go back to `psql` and check the contact you just updated:

```sql theme={null}
db7hea89oah3tas=> select firstname, lastname from contact where id='{{contact_id}}';

 firstname | lastname
-----------+----------
 Sequin    | Setup
(1 row)

```

Great, Salesforce and your database were updated simultaneously.

## Next steps[](#next-steps "Direct link to Next steps")

Your Salesforce tables are now available as fully readable and writeable tables in your database. You can query for all your data using SQL, and mutate data thanks to Sequin's Postgres Proxy. To build on this foundation, here are some next steps:

* [Setup your ORM](/docs/reads) to work with your synced tables.
* Edit the Salesforce objects and properties you're syncing at any time.
* Create [views](https://www.postgresql.org/docs/current/tutorial-views.html) on your Salesforce data to tailor your schema to your needs.
* Invite your team to your Sequin account and start building!

If you need assistance setting up your sync, just [send us a note](mailto:support@sequin.io). We're around and eager to help.
