# Salesforce (Legacy)

{% hint style="info" %}
This reference documentation is for the **Legacy** Salesforce book. Refer to the latest version [**here**](https://docs.kognitos.com/legacy/legacy-experience/books/reference/salesforce).
{% endhint %}

## Introduction

The **Salesforce Book** integrates with Salesforce, allowing you to interact with Salesforce data and functionalities. This integration enables users to perform a wide range of operations on Salesforce objects, including querying, creating, updating, and deleting records, and managing files.

## Prerequisites

1. **Salesforce Account**: You need to have an active Salesforce account. If you do not have one, you can sign up for a Salesforce trial account to get started.
2. **API Access**: Ensure that your Salesforce account has API access enabled. API access is required for Kognitos to communicate with Salesforce.
3. **Security Token**: Obtain your Salesforce security token, which is used in conjunction with your password to access Salesforce via the API securely. You can find this in your Salesforce settings under "My Personal Information" > "Reset My Security Token". You may need to contact your company’s IT support for the security tokens.

#### Required Credentials

To connect to Salesforce, you will need the following credentials:

1. **Salesforce Instance URL**: The base URL of your Salesforce instance. This URL is unique to your organization and can be found in the address bar when you are logged into Salesforce. It typically follows the format `https://<your_instance>.salesforce.com`.
2. **Username**: The email address or username associated with your Salesforce account.
3. **Password**: The password for your Salesforce account.
4. **Security Token**: A security token is an automatically generated key from Salesforce that adds an extra layer of security on top of your password. If you're accessing Salesforce from an untrusted network, you'll need this token. You can obtain your security token by navigating to your Salesforce settings and requesting a new token. Salesforce will email the token to the email address associated with your account.

## Learning the Salesforce Book

1. Navigate to **Books → All Books.**
2. Search for **Salesforce** and click on it.
3. Click on **Add Connection**.
4. Enter your credentials when prompted.

## Procedures

### Fetching Data using custom SQL queries

To fetch data from Salesforce using custom SQL queries:

```
fetch the records from salesforce where
  the query is "SELECT Id, Email FROM Contact"
```

### Fetching Data using Direct Queries

To fetch data from Salesforce using direct queries:

```
get salesforce's leads whose annual revenue is less than 1000000000
```

### Adding New Records

To add a new record to Salesforce, you need to specify the type of object you're creating and provide the necessary field values. Example:

```
the opportunity is
    the name is "New Deal"
    the close date is "2023-12-31"
    the stage is "Prospecting"
add the opportunity in salesforce
```

This creates a new opportunity named "New Deal" with a close date and stage specified.

### Updating Existing Records

To update an existing Salesforce object, you must identify the object by its ID and specify the fields you want to update. Example:

```
the opportunity's ID is "006xx000001Sv6aAAC"
change the opportunity's stage to "Closed Won" in salesforce
```

This updates the stage of the specified opportunity to "Closed Won".

### Deleting Salesforce Objects

To delete a specific Salesforce object, you need to specify the object and its ID. For example:

```
the salesobject's ID is "006xx000001Sv6aAAC"
delete the salesobject
```

This command deletes the sales object with the specified ID.

### Creating a new lead in Salesforce

To create a new lead in Salesforce:

```
Create a lead in salesforce with
  the lead status is "New"
  the last name is "Hackmann Test"
  the company is the lead company
  the email is the lead email
  the lead source is "Other Campaigns"
```

### Submitting Sales Objects for Approval

This is the syntax for submitting a Salesforce object for approval in Kognitos:

```
submit the opportunity for approval with
    the opportunity's ID is "006xx000001Sv6aAAC"
    the comment is "Requesting approval for high-value opportunity"
```

In this example, an opportunity is submitted for approval by specifying its ID and providing a comment to give context to the approver. Kognitos translates this command into the appropriate Salesforce operation, automating the submission process.

### Creating Salesforce Reports

Creating a report in Salesforce involves selecting the type of report, defining the criteria, and choosing the fields to display. With Kognitos, you can articulate these requirements in a more intuitive manner. For instance, you can specify the type of report you need, the records it should cover, and any specific conditions that must be met.

```
create a report in salesforce with
    the report name is "Quarterly Sales Summary"
    the report type is "Tabular"
    the fields are "Account Name", "Close Date", "Amount"
    the filter is "Close Date this quarter"
```

This tells Kognitos to create a Salesforce report for opportunities from the last quarter, including specific fields. Kognitos translates this into the appropriate Salesforce report creation process, selecting the correct report type and applying the specified filters.

### Attaching Files to Salesforce Objects

Example: Attaching a PDF Contract to an Account

```
attach the file to the salesforce object with
    the file path is "/path/to/contract.pdf"
    the salesforce object's ID is "001xx000003DHP0AAO"
    the file type is "PDF"
```

This specifies the file to attach (`contract.pdf`), identifies the Salesforce object by its ID, and indicates the file type. Kognitos handles the process of attaching the file to the specified Salesforce object.

### Downloading Files from Salesforce Objects

Example: Downloading a Contract Attached to an Account

```
download the file from the salesforce object with
    the salesforce object's ID is "001xx000003DHP0AAO"
    the file name is "contract.pdf"
```

This retrieves an attached file (`contract.pdf`) from a specified Salesforce object. Kognitos facilitates the download process, making the file available for local use or review.

### Detaching Files from Salesforce Objects

Example: Removing an Outdated Contract from an Account

```
detach the file from the salesforce object with
    the salesforce object's ID is "001xx000003DHP0AAO"
    the file name is "old_contract.pdf"
```
