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

# Setup

> Connect to your users’ Salesforce CRM to create, access, and update records in their Salesforce account.

### Pre-requisites

1. Salesforce Developer Account.
2. Required Settings for the App. You can find it in [Overview](https://docs.gocobalt.io/resources/integration-providers/salesforce_overview#required-settings).
3. `Unlimited`, `Developer` or `Enterprise` Edition Salesforce account required if you want to use Triggers.

<Info>
  Salesforce triggers work using Apex classes which are offered only on limited plan types of Salesforce. Refer [here](https://help.salesforce.com/s/articleView?id=platform.code_define_package.htm\&type=5).
</Info>

<Note>
  While calling Salesforce API, you might get the error `The REST API is not enabled for this Organization.` To solve this, go to `Manage User` -> `User` -> `System Administraiton` -> `Administrative Permission` -> Check **API Enable** checkbox.
</Note>

### Creating an app in Salesforce

To create a Salesforce app and acquire the app credentials, please follow the steps mentioned below:

1. Log in to your Salesforce dashboard with your developer account credentials.
2. Click on the `Gear` icon in the top right and select `Open Advanced Setup` button.

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_navigate.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=5fee3e458aff8709d147ed3b36e38ac1" alt="Navigation for App setup" data-path="images/Salesforce/Salesforce_navigate.png" />

3. Select `Apps` > `App Manager` options from the left side menu under `Platform Tools` section.
4. Select `New Connected App` button in the setup page.
5. Enter the basic details of your application
6. Under **API (Enable OAuth Settings)**, mark the `Enable OAuth Settings` checkbox.
7. Enter the Callback URL as provided in your Salesforce settings page in Refold. Go to your [`Apps catalog`](https://app.gocobalt.io/apps) > Search for `Salesforce` > `Settings` > `Use your credentials` > `Callback Url`.
8. Select the required scopes, atleast the scopes selected in your Refold Salesforce settings page.
9. Enable the following **App Settings**, click on the `Save` button and click `Continue`.
   * Require Secret for Refresh Token flow
   * Enable Authorization Code and Credentials Flow
   * Enable Token Exchange Flow
   * Require Secret for Token Exchange Flow
   * Issue JSON Web Token (JWT)-based access tokens for named users

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_config.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=0d33aab9c6c93d5f4cb5dd06c125cb0c" alt="Setting up Salesforce Developer app" data-path="images/Salesforce/Salesforce_config.png" />

10. Click on the `Manage Consumer Details` button under the API (Enable OAuth Settings) section, verify your identity and copy the **Consumer Key** and **Consumer Secret**.

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_credentials.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=33c4fd1ce99a84649afd49f6aefbddbb" alt="Getting Credentials" data-path="images/Salesforce/Salesforce_credentials.png" />

#### Configuring credentials in Refold

App settings page lets you configure the authentication settings for an `OAuth2` based application. For your customers to provide you authorization to access their data,
they would first need to install your application. This page lets you set up your application credentials.

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_cobalt.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=9fff30e5ef118c2a682aea6f5fecff25" alt="Setting up application client credentials" data-path="images/Salesforce/Salesforce_cobalt.png" />

Provide the acquired Client ID and Client Secret under Settings of the app and save it.

#### Configuring Scopes

Refold lets you configure what permissions to ask from your users while they install your application. The scopes can be added or removed from the App settings page, under `Permissions & Scopes`
section.

For some applications Refold sets **mandatory scopes** which cannot be removed. Additional scopes can be selected from the drop down. Refold also has the provision to add any
custom scopes supported by the respective platform.

<img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_scopes.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=2eaa9c1c607536bc259a6d8f946224bf" alt="OAuth Scopes" data-path="images/Salesforce/Salesforce_scopes.png" />

Once the scopes has been added to the application in Refold, go to your [Salesforce developer account dashboard](https://developer.salesforce.com) and update the scopes as added on Refold.

Navigate to  `Apps` > `App Manager` > Select the OAuth App created for Refold > Click on the dropdown menu > Select  `Edit` > `Selected OAuth Scopes` > Add the scopes as added in Refold and click on `Save`.

<Warning>
  If you are facing scopes missing or invalid scope error. Make sure you are not passing any custom scope not supported by the platform. And, the scopes selected here are
  identical to the ones selected in the platform.
</Warning>

#### Salesforce Webhooks

To use Salesforce webhooks as triggers in your workflows, your end-users need to add the API base URL of Refold as a Remote Site in Salesforce to receive the events successfully.

Follow these steps to add as Remote Site:

<Steps>
  <Step title="Navigation">
    Login to your Salesforce and in **Setup**, search for `Remote Site Settings` which will be present under **Security** and select it.

    <img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_remote.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=604bf6b77e7644564191e235fa5e42a5" alt="Remote Site Settings in Salesforce" data-path="images/Salesforce/Salesforce_remote.png" />
  </Step>

  <Step title="Add Remote Site">
    Click on `New Remote Site` button.
  </Step>

  <Step title="Add URL">
    Provide a **Name** of the Remote Site, add `https://api.gocobalt.io` under **Remote Site URL** and click on `Save`.

    <img height="200" src="https://mintcdn.com/cobalt-55/JZIwRzAqkgW8vPoP/images/Salesforce/Salesforce_remote_2.png?fit=max&auto=format&n=JZIwRzAqkgW8vPoP&q=85&s=2ab5f11b277f74d1df0e080316e81bbd" alt="Remote Site Settings in Salesforce" data-path="images/Salesforce/Salesforce_remote_2.png" />
  </Step>
</Steps>

<Check>
  You have successfully added the API base URL of Refold in Salesforce for the triggers.
</Check>
