# Before you create a Salesforce workspace

## Configure Salesforce as an Identity Provider <a href="#salesforce-identity-provider" id="salesforce-identity-provider"></a>

You must [enable Salesforce as an Identity Provider](https://help.salesforce.com/s/articleView?language=en_US\&id=identity_provider_enable.htm\&type=5).

This is required for authentication between Salesforce and Structural. It is independent of any existing Salesforce single sign-on (SSO) user login.

## Enable Grant API Enabled Access <a href="#salesforce-api-enabled-access" id="salesforce-api-enabled-access"></a>

You must [enable Salesforce with Grant API Enabled Access.](https://help.salesforce.com/s/articleView?id=sf.branded_apps_commun_api_permset.htm\&type=5)

This is required for authentication between Salesforce and Structural.

## Creating the connected Salesforce application for Structural <a href="#salesforce-create-connected-app" id="salesforce-create-connected-app"></a>

For the integration between Structural and Salesforce:

* Salesforce is set up as an Identity Provider for Structural
* OAuth bearer tokens are used to transparently access Salesforce from Structural.

There are no separate passwords or user secrets. Each user is limited to only the data available based on their available level of access for their Salesforce or Structural account.

### **Create the application in Salesforce** <a href="#salesforce-create-app" id="salesforce-create-app"></a>

1. Log into your Salesforce instance.
2. Make sure that Salesforce is enabled as an [Identity Provider](https://help.salesforce.com/s/articleView?language=en_US\&id=identity_provider_enable.htm\&type=5) with [Grant API Enabled Access](https://help.salesforce.com/s/articleView?id=sf.branded_apps_commun_api_permset.htm\&type=5).
3. In the top right corner, click the gear icon, then click **Setup**.

<div data-full-width="false"><figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FVrxeNsXnhYIGJYH6INBf%2FSalesforce_CreateAppSelectSetup.png?alt=media&#x26;token=909390f8-83fd-473b-b16d-a0e4e3c5a699" alt=""><figcaption><p>Setup menu</p></figcaption></figure></div>

4. On the **Setup** page, in the search field, enter **App Manager**, then select **App Manager**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FqTJa63ds9LuWj7Wn0oOy%2FSalesforce_CreateAppFindAppManager.png?alt=media&#x26;token=09ea71ac-5d9e-4ea4-b8f1-433791604e0c" alt=""><figcaption><p>Using the search field to find the App Manager</p></figcaption></figure>

5. Click **New Connected App**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2Fii2l8IVVag3BjLJdYFlY%2FSalesforce_CreateAppNewConnectedApp.png?alt=media&#x26;token=49cd2ffc-f1cc-4c95-8968-788faa556f1d" alt=""><figcaption><p>Option to create a new connected application</p></figcaption></figure>

6. On the **Create a Connected App** panel, click **Create a Connected App**.
7. On the **New Connected App** page, under **Basic Information**, fill in the following fields:
   * **Connected App Name**. We recommend that you include '`Tonic`' somewhere in the name. Note that after you create a connected app, you cannot change the name.
   * **API Name**
   * **Contact Email**

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FODJXhxihvk3H2rMiY2DC%2FSalesforce_CreateAppBasicInformation.png?alt=media&#x26;token=34824e9c-8f43-4cc6-bbc6-4b4ce1d933f1" alt=""><figcaption><p>Basic Information section for connected application creation</p></figcaption></figure>

8. Under **API (Enable OAuth Settings)**:
   1. Check **Enable OAuth Settings**.
   2. In the **Callback URL** field, enter the URL of your Structural instance with `/oauth2/callback` appended to it.\
      \
      For a self-hosted instance, if you do not have access to the Structural URL, contact the Structural administrator at your organization. If your organization has deployed more than one Structural instance, you can enter multiple URLs.\
      \
      For Structural Cloud, the callback URL is `https://app.tonic.ai/oauth2/callback`.<br>
   3. Under **Selected OAuth Scopes**, move the following settings from **Available OAuth Scopes** to **Selected OAuth Scopes**:
      * **Manage user data via APIs (api)**
      * **Perform requests at any time (refresh\_token, offline\_access)**
   4. Leave the currently checked checkboxes checked.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FTuKWuncZ8tysqI6vk6sS%2FSalesforce_CreateAppOathSettings.png?alt=media&#x26;token=276b999d-c4ca-4082-9944-30e0ff5d9f2e" alt=""><figcaption><p>API (Enable OAuth Settings) section for connected application creation</p></figcaption></figure>

9. Navigate to the bottom of the page, then click **Save**.

### Retrieve the consumer key and secret <a href="#salesforce-connected-app-get-consumer-key-secret" id="salesforce-connected-app-get-consumer-key-secret"></a>

After you save the new application, to retrieve the consumer key and secret values:

1. Expand the **API (Enable OAuth Settings)** section, then click **Manage Consumer Details**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FbGhbYTnVjwTP7dGL0x7r%2FSalesforce_CreateAppManageConsumerDetails.png?alt=media&#x26;token=191b46de-9120-42ba-8e01-5fd3f446c732" alt=""><figcaption><p>Manage Consumer Details option on the application details page</p></figcaption></figure>

2. Locate and copy the values of **Consumer Key** and **Consumer Secret**. You use these to populate the consumer key and secret values in Structural.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FB5ciwuXQH2leYnkChDyQ%2FSalesforce_CreateAppGetConsumerKeySecret.png?alt=media&#x26;token=87852401-4a98-47a5-a35a-0b6936e190c7" alt=""><figcaption><p>Consumer Key and Consumer Secret fields for the new application</p></figcaption></figure>

### **Set the consumer key and secret Structural environment settings** <a href="#salesforce-app-env-settings" id="salesforce-app-env-settings"></a>

Configure the following [Structural environment settings](https://docs.tonic.ai/app/admin/environment-variables-setting), which you can configure from the **Environment Settings** tab on **Structural Settings**:

* `TONIC_SALESFORCE_CONSUMER_KEY` - Set to the consumer key value that you copied from Salesforce.
* `TONIC_SALESFORCE_CONSUMER_SECRET` - Set to the consumer secret value that you copied from Salesforce.

If you do not configure these environment settings, then you must provide the consumer key and consumer secret in the workspace configuration. For example, on Structural Cloud, you must always configure the consumer key and secret in the workspace.

### Confirming the connected application permissions <a href="#salesforce-connected-app-confirm-permissions" id="salesforce-connected-app-confirm-permissions"></a>

After you set up the connected application, the first time that you log in to Salesforce with the user that connects from Structural, Salesforce displays a warning about the additional permissions that are granted to the connected application.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FZfpiCmIOsXhcLZbGwulp%2FSalesforce_ConnectedAppConfirmPermissions.png?alt=media&#x26;token=d9f921b5-7cfa-40e8-8d03-47368e08b18a" alt=""><figcaption><p>Confirmation panel for the connected application permissions</p></figcaption></figure>

This first login is likely to occur the first time you configure a workspace connection.

It prompts you to confirm those permissions.

If you do not confirm the permissions, then Structural is unable to connect to Salesforce.&#x20;

## Creating the source and destination connections <a href="#salesforce-source-dest-connections" id="salesforce-source-dest-connections"></a>

For a Salesforce workspace, the source and destination data connections must be separate orgs.

The source and destination connections can be production orgs, sandbox orgs, or scratch orgs.

However, the destination connection can only be a scratch org if the source connection is also a scratch org.

## Ensuring required Salesforce user permissions <a href="#salesforce-user-permissions" id="salesforce-user-permissions"></a>

Salesforce users who authorize Structural to connect on their behalf must have the following permissions configured[:](https://docs.tonic.ai/app/api/example-polling-for-a-job-status-+-creating-a-docker-package)

* Granted the `Marketing User` option.
* Assigned a role that has edit access for all of the opportunities and cases. In the example below, `All Access` is an example of a custom role that was granted the required access.
* Assigned the `System Administrator` profile.
* Granted the `Manage Users` permission. If the permission is not included in the `System Administrator` profile, then you must grant it separately.
* Granted the additional permission `Update Records with Inactive Owners`.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FgOrynTxt4zJbsGI69fxJ%2FSalesforce_EnsureRequiredUserPermissions.png?alt=media&#x26;token=b7d0a01d-dc95-470a-a118-f6f206067fab" alt=""><figcaption><p>User details with required permissions highlighted</p></figcaption></figure>

### Making the Update Records with Inactive Owners permission available to grant <a href="#salesforce-enable-addition-permission" id="salesforce-enable-addition-permission"></a>

Before you can grant the `Update Records with Inactive Owners` permission, you must make sure that it is available to grant.

To make the permission available:

1. Go to **Setup > User Interface.**
2. Check the **Enable** **“Set Audit Fields upon Record Creation” and “Update Records with Inactive Owners” User Permissions** checkbox.
3. Click **Save**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FqUUCu0VPy4U5rolz750B%2FSalesforce_MakeUpdateRecordsWithInactiveOwnersAvailable.png?alt=media&#x26;token=205e50a4-3622-4f9f-b7d3-6b07b6e030d3" alt=""><figcaption><p><strong>Enable</strong> <strong>“Set Audit Fields upon Record Creation” and “Update Records with Inactive Owners” User Permissions</strong> checkbox</p></figcaption></figure>

### Granting the Update Records with Inactive Owners permission <a href="#salesforce-permission-additional-grant" id="salesforce-permission-additional-grant"></a>

After you enable the permission, to grant it, you can create and assign a permission set.

To display the permission sets page:

1. Go to **Setup**.
2. Under **Administration**, click **Users**, then **Permission Sets**.

#### Creating the permission set <a href="#create-permission-set" id="create-permission-set"></a>

To create the permission set:

1. On the **Permission Sets** page, click **New**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FNmQZT1qpu6Nb7EJb9Mx8%2FSalesforce_PermissionSetsNew.png?alt=media&#x26;token=610c3a60-8030-42bb-a693-8d9fbe69e3ad" alt=""><figcaption><p>New button to create a new permission set</p></figcaption></figure>

2. In the **Label** field, provide a name for the permission set.
3. Leave **License** set to **None**.
4. Click **Save**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FqzqQwNpHXQh6Zf2t9MnN%2FSalesforce_PermissionSetConfigureNew.png?alt=media&#x26;token=b3108d7f-7144-4b5f-80c9-9ec15d5a136e" alt=""><figcaption><p>Creating a new permission set</p></figcaption></figure>

#### Assigning the permission to the permission set <a href="#assign-permission-to-permission-set" id="assign-permission-to-permission-set"></a>

To assign the permission to the permission set:

1. On the **Permission Sets** page, under **System**, click **System Permissions**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FwGBI3UsvlGl7oVzzjBNW%2FSalesforce_PermissionSetsSystem.png?alt=media&#x26;token=c9a2a3c8-e427-43e8-9a89-75df3181c9ec" alt=""><figcaption><p>System section on the Permission Sets page</p></figcaption></figure>

2. Under **System Permissions**, click **Edit**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FLBn79s6KMe8je8HOyzYJ%2FSalesforce_SystemPermissionsEditOption.png?alt=media&#x26;token=4432f403-a030-47f9-a5b7-7b9cdb5d5078" alt=""><figcaption><p>Edit option for the system permissions</p></figcaption></figure>

3. Check the `Update owner and sharing-based fields with Inactive Owners` permission.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FmkhulFctEDsuSqkdtduE%2FSalesforce_PermissionSetUpdateRecordsWithInactiveOwners.png?alt=media&#x26;token=13269d5a-f8be-4373-8536-a64bbd009937" alt=""><figcaption><p>Enabling the Update owner and sharing-based fields on records with inactive owners permission</p></figcaption></figure>

4. Click **Save** and then confirm your changes.

#### Assigning the permission set to the user

To assign the permission set to your user:

1. From the permission set details, click **Manage Assignments**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FgDe2aM0JOahNj5D3NAy3%2FSalesforce_PermissionSetManageAssignments.png?alt=media&#x26;token=b6a56cde-e3e2-405e-9221-7e7028d7dc2c" alt=""><figcaption><p>Manage Assignments option for the permission set</p></figcaption></figure>

2. On the **Current Assignments** page, click **Add Assignment**.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2FzYb0nQ0VbB0ja0mcuYSr%2FSalesforce_PermissionSetAddAssignmentOption.png?alt=media&#x26;token=f7970eb4-5323-4979-8a89-7a023b855131" alt=""><figcaption><p>Add Assignment option for a permission set</p></figcaption></figure>

3. On the **Select Users to Assign** page, elect the user or users that you intend to use with Structural.

<figure><img src="https://3378426797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSQCLFQ4bslJ-HYc8c3%2Fuploads%2Ff2hpK8ckTrtnwYcb51AA%2FSalesforce_PermissionSetSelectUsers.png?alt=media&#x26;token=1f0d8c59-29e8-4fd7-a85e-827913d3ff7b" alt=""><figcaption><p>Select Users to Assign page for a permission set</p></figcaption></figure>

4. Click **Next**, then confirm the permission set assignments.

## Enabling the ability to de-identify Salesforce users

Salesforce workspaces include an [option to de-identify destination users](https://docs.tonic.ai/app/setting-up-your-database/salesforce-workspace-data-connections#salesforce-deidentify-users).

To allow this option, in the **User Management Settings** for the destination org, you must enable **Scramble Specific Users’ Data**.


---

# 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.tonic.ai/app/setting-up-your-database/salesforce/salesforce-before-workspace.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.
