Salesforce Integration

Example Site
To see a live example, click here.

The Salesforce Integration package provides you with the ability to easily monitor and manage data records in your Salesforce account from a Wix site. You can perform the following actions with this package:

  • Query: Query data records in Salesforce.
  • Retrieve: Retrieve data records from Salesforce.
  • Create: Create new data records in Salesforce.
  • Update: Update data records in Salesforce.
  • Delete: Delete data records from Salesforce.

To see an example site that demonstrates how to use this package, click here.

Setup

Before using the package, set up the following:

Salesforce Platform

  1. Go to the Salesforce developer site and complete the registration process, or sign in if you already have a Salesforce developer account.
  2. On the top right corner, Click your avatar and navigate to My Developer Account.
  3. On the top right corner of your developer dashboard, click your avatar and go to Settings.
  4. In the Personal Information dropdown on the left, click Reset My Security Token.
  5. Complete the reset process and get your security token.

Wix Platform

Secrets Manager
  • Open the Wix Secrets Manager and create a new secret with the name velo-salesforce-credentials. Store the following JSON object in the secret:

    Copy

    Note: Make sure that the object is in correct JSON format, including all quotes. If not, the Secrets Manager will not be able to read the object properly, resulting in incorrect Salesforce credentials.

Package Content

The following backend files are included in the package. Note that only exported functions that you can use in your site are listed here.

salesforce.js

The code in this file contains functions for querying, retrieving, creating, updating, and deleting data records from Salesforce.

To use the functions below in your backend code, import them with the following syntax:

Copy

The file contains the following functions:

  • queryRecords()

    Queries a Salesforce object using an SOQL command and returns the data records that match the criteria specified in the command.

    Copy
  • retrieveRecords()

    Retrieves data records with the specified IDs from a Salesforce object.

    Note that you can only use this function when you know the IDs of the records you want to retrieve in advance. Use the queryRecords() function instead to get the records when you don’t know the IDs, or to specify other selection criteria.

    Copy
  • createRecords()

    Creates one or more records of a specific Salesforce object.

    Copy
  • updateRecords()

    Updates specified data records in a specific Salesforce object.

    Copy
  • deleteRecords()

    Deletes specified data records in a specific Salesforce object with the specified IDs.

    Copy
Parameters
  • sfObjName: Name of the Salesforce object (for example, Account). See the list of all Salesforce objects here.
  • queryStr: An SOQL command specifying what to query.
  • ids: Array of record IDs for a Salesforce object. Each instance of a Salesforce object is called a record.
  • records: Single or array of record objects. Each instance of a Salesforce object is called a record.

How to Use the Package

This section demonstrates how you can work with the package, and the different options for using the package functions.

Create Data Records in Salesforce

The following describes how you can use this package to add a new Salesforce object instance (record). In our example, we demonstrate how to create a new Account object record, but you can use the code to create one or more records for any Salesforce object type. In our example, we create the record with the Name and Phone fields, but you can adapt the code to create records with any fields. .

  1. To use the createRecords() function in your page code, add a web module to your backend. We’ll call ours salesforce-wrapper.jsw. Include the following code in this file:

    Copy
  2. Add the following page elements to your site:

    • 2 text inputs for adding the record data.
    • Button to trigger record creation.
    • Text element for validation messages.
  3. Import the createRecordsWrapper() function from the web module to your page code and run it when the button is clicked. Call the createRecordsWrapper() function to create the record with data from the input elements.

    Copy

Query Data Records from Salesforce

The following describes how you can use this package to query a phone number from a specific Account record (Salesforce object) based on the record name. If you want to query a different field or a different Salesforce object type, simply adapt the code for your use case.

  1. To use the queryRecords() function in your page code, add a web module to your backend. We’ll call ours salesforce-wrapper.jsw. Include the following code in this file:

    Copy
  2. Add the following page elements to your site:

    • Text input for getting the record name.
    • Text element for displaying the returned data.
    • Button to trigger the query.
    • Text element for validation messages.
  3. Import the getPhoneBasedOnName() function from the web module to your page code and run it when the button is clicked to query the records.

    Copy

npm Packages

This Velo package uses the following npm package. To view the npm license, see the npm readme.

Release Notes

1.0 Initial version.

Tags

salesforce, jsforce, sales

Did this help?