Salesforce Guide
Last updated
Last updated
Salesforce is a leading customer relationship management (CRM) platform.
Salesforce offers a REST API that allows you to integrate with third-party applications such as Linx. This enables you to automate tasks and data processing capabilities to integrate with your instance of Salesforce, allowing the manipulation of your data.
Linx allows you to easily extend the functionality of Salesforce as well as integrate Salesforce with other third-party applications such as Xero, QuickBooks, and other system APIs. This creates a completely automated loop by joining systems together.
The following will be covered in this guide:
Setup of a Salesforce connected app and OAuth 2.0 authentication
Authenticating and connecting to the Salesforce API
Example requests
Example of custom functions
To interact with the Salesforce API, you must first register a connected application. This will provide you with the necessary authorization details, which you can then use to generate your Access and Refresh tokens.
Log in to the Salesforce front-end.
Navigate to the App Manager console (Left menu bar > Apps > App Manager).
Click New connected App in the top-left corner of the screen.
Complete the basic information as shown below:
Select Enable OAuth Settings ✓ and complete the section as shown below:
For the Callback URL / Redirect URL, add the following:
http://localhost:8080/salesforce/oauth/token
Add your chosen access “scopes” by clicking the ► button. For this guide, we will grant:
Full access (full)
Perform requests on your behalf at any time (refresh_token, offline_access)
Click Save.
You should now be able to see your newly created app's client identifiers like below:
10. Click **Click to reveal** next to the **Consumer Secret** to generate and show an app secret. 11. Copy and save the **Consumer Key (Client ID)** as well as the **Consumer Secret (Client Secret)** and store these somewhere for the next step.
Open the provided sample solution in the Linx Designer and update the $.Settings
of the Linx application with the client identifiers like below:
salesforce_app_consumer_key
: Your connected app’s Consumer Key
salesforce_app_consumer_secret
: Your connected app’s Consumer Secret
Your Linx solution’s $.Settings
should look like below:
In the Linx Designer, debug the RESTHost. Once started, navigate to the below URL:
http://localhost:8080/salesforce/oauth/authorize
Login to Salesforce and grant access to your registered app.
Once you’ve granted access, the Salesforce authorization server will redirect the user-agent to the Callback URL with the code and state parameters.
This will trigger the access token generation. If successful, the resulting message should be displayed in your browser like below:
{ "date": "2021-01-05T13:33:29.36004+02:00", "summary": "Linx application successfully authorized.", "platform": "SALESFORCE", "authorized_entity": "https://yu8.salesforce.com" }
This indicates that Linx has successfully generated and stored the access token in the database. This token information will be retrieved from the database each time a request is made.
Now that the Linx application has been granted access and the access token has been generated, you can now make CRUD requests against objects in your instance of Salesforce.
To make HTTP requests in Linx, you must use the CallRESTEndpoint.
To make requests against a Salesforce API endpoint, you must prefix the endpoint URL with your instance of Salesforce like below:
{instance url}/services/data/v{version number}/sobjects/Account
In order to authenticate the request, you must include the access token in the Authorization header like below:
Authorization : "OAuth " + {access token}
The Salesforce API reference documentation does not describe in detail each object, endpoint, or methods.
To work with sObjects on Salesforce, you need to make requests against the API which return the structure of the objects. From this, you will be able to create the appropriate data structures.
You can return the metadata of an sObject by making a request like below:
{instance url}/v50.0/sobjects/{sObjectName}/describe/
This will give you detailed metadata on what’s possible with the object.
The below custom functions have been built to demonstrate the best practice of creating stand-alone functions that make a single request. Each function returns the request response as structured data.
For this demonstration, we will detail the “Account” object.
The following custom functions can be located in the Solution Explorer: [Salesforce] > [Accounts] > [Requests]
A best practice to follow is to create a wrapper function for each type of call like below:
GetAccounts: Retrieves all existing Account IDs from Salesforce and returns the list of objects as the result.
GetAccount: Retrieves the detailed information associated with a specific account based on the ID input parameter. This can be used to check modification history as well as used to update the sObject.
CreateAccount: Creates a new account based on the Account details passed in as the input parameter.
UpdateAccount: Modifies an existing account based on the Account details passed in as the input parameter.
DeleteAccount: Removes an existing account based on an ID input parameter.
You will then be able to use these functions interchangeably to create custom logic to automate data processing on Salesforce.
Typical Structure:
The below custom functions have been built to demonstrate real-world functionality.
The following custom functions can be located in the Solution Explorer: [Salesforce] > [Accounts] > [CustomFunctions]
This custom function handles the creation or modification of Account entities retrieved from a local CSV file.
A FileList function performs a scan of a local directory filtering for files in the format of customers.csv. For each file matching the filter, the full FileName property is returned.
For each file picked up, a TextFileRead function parses the file and returns each row, one-by-one, in a structured format.
For each line that is returned, an instance of an “Account” type is set to the details returned from the file.
A search is then performed on Salesforce for an Account matching the name from the file. The custom function SearchObject takes in an input parameter of the current line’s name details.
This will return the ID of any matching records.
An IfElse function checks if any matching ID values were returned. If a matching ID does exist, the specific details of the Account matching the ID are retrieved using the custom function GetAccount.
A check is done using an IfElse function to compare the last modified field from the file to the last modified field returned from Salesforce. If the data from the file is more recent than the record on Salesforce, the account details are updated using the custom function UpdateAccount, passing in the “Account” type that was set earlier.
If the Account does not exist on Salesforce, it is created using the custom function CreateAccount, passing in the “Account” type that was set earlier. The newly created ID is then returned. This ID is added to a list containing the recently added Accounts.
Once the particular file has finished reading, it is moved to a “backup” location using a FileMove function.
The list of Accounts is then looped through and appended to a local CSV file for record-keeping purposes.
This function inserts the details of all the accounts from Salesforce into a local CSV file.
First, a TextFileWrite function resets the local file with the headers of the columns.
All existing Account IDs are retrieved using the custom function GetAccounts. A loop is performed on the list of Account IDs returned using a ForEach function.
For each Account, the custom function GetAccount is executed, passing the current loop’s ID field value as an input parameter. The specific account’s details are then returned as a result.
The returned Account’s details are then written line by line as a CSV file using a TextFileWrite function.
Resulting File:
This custom function removes all existing accounts from Salesforce.
First, all existing Account IDs are retrieved using the custom function GetAccounts. A loop is performed on the list of Account IDs returned using a ForEach function.
For each Account, the custom function DeleteAccount is executed, passing the current loop’s ID field value as an input parameter. The specific account is then removed from your Salesforce instance.
Caution: This will remove all accounts currently on Salesforce - proceed with caution.
Note: If you select different scopes, be sure to update the $.Settings.salesforce_app_scopes
value appropriately. More information on the scope of access can be found .
linx_database_conn_string
: Connection string used for storing and retrieving the authentication token from a database. Read more about creating connection strings .
salesforce_api_version
: Current version of the API, at the time of writing it is v50.0, and may change. The latest version information can be found .
More information can be found .
View our sample solution on .