In my last tutorial, we integrated Salesforce with a local Drupal installation. In this tutorial, we will continue to build off from what we learned and pull data from Salesforce into Drupal.
For those of you who didn't read my last tutorial, I will repeat a few crucial steps needed to get us started.
If you don't already have a Salesforce account, you can create a free developer account by following the steps below.
- Go to https://developer.salesforce.com/signup and apply for an account
- Check your email for confirmation, and verify your account
- You can now access your account by going to https://login.salesforce.com/
In order to connect your local Drupal install with your Salesforce account, you'll need to install and enable the Salesforce Suite module.
In order to authenticate your Salesforce account with Drupal, you need to create a connected app in Salesforce. Follow these steps to create a connected app, and authenticate Salesforce with Drupal.
- Login to your Salesforce account at https://login.salesforce.com/
- Under Build Click Create > Apps
- Then under Connected Apps click New **
Fill out the following fields:
- Connected App Name
- API Name
- Contact Email
- Select Enable OAuth Settings
- The Callback URL will be https://your-example-site/salesforce/oauth_callback. Note that you can find this at admin/help/salesforce on your local Drupal install
- Select Perform requests on your behalf at any time and add it to the Selected OAuth Scopes column
- I also needed to add Full access (full) to the Selected OAuth Scopes column
- Save. You'll get a message alerting you that you app will be ready to authenticate within 2-10 minutes.
- In Salesforce under Quick Links click Manage Apps. Then under Connected Apps click the name of the app to see the Consumer Key and Secret Key
Back on your local Drupal install go to the Salesforce Authorization page at admin/config/salesforce/authorize
- Add your consumer and secret key
- Under advanced, add the Salesforce endpoint. This will be the domain you see in your address bar when logged into your Salesforce account. In my case it's https://na34.salesforce.com
- Click Authorize and follow the prompts
- Add your consumer and secret key
In order to pull data from Salesforce into Drupal, we need to create fields for the data mapping. For this tutorial, I'm going to use the default contacts that come with a free Salesforce developer account. Specifically, I'm going to use the Salutation , First Name , Last Name fields. I'm also going to create a custom content type to serve as the entity to map the data to.
Enable Salesforce Mapping and Salesforce Pull
- Navigate to admin/structure/salesforce/mappings
- Select Node under Drupal Entity Type
- Select Contact under Drupal Entity Bundle
- Select Contact under Salesforce object
Configure the following under the FIELD MAP section
Under the DRUPAL FIELD column, select Properties and then the fields we created earlier.
- I also mapped Full Name to the Title field.
Under the SALESFORCE FIELD column, select the Salesforce field that you wish to map to.
- ProTip: Use Chosen to help search the Salesforce fields.
- Under the DIRECTION select SF to Drupal for all fields
Under Action triggers select the following:
Now that we've mapped our Salesforce fields with our Drupal fields, we can finally import data into Drupal. The simplest way to do this is to run cron. However, I ran into an issue where running cron simply didn't pull in any data. To fix this, you need to delete the
- Run the following command
drush vdel salesforce
- You will see an output similar to below. Enter the number that corresponds with the
salesforce_pull_last_syncvariable you wish to delete. If you're mapping more than one Salesforce Object, there will be more than one
Enter a number to choose which variable to delete.  : Cancel  : salesforce_consumer_key  : salesforce_consumer_secret  : salesforce_endpoint  : salesforce_identity  : salesforce_instance_url  : salesforce_pull_last_sync_Contact  : salesforce_refresh_token
- Run cron
I absolutely struggled connecting Salesforce and Drupal on my first project. The two main issues I ran into were the following:
- I couldn't pull data into Drupal from Salesforce until I deleted the
salesforce_pull_last_syncvariable and ran cron
- Fields need to be the same field type in Salesforce and Drupal. For example, text fields map to text fields. List fields maps to list fields.
Also, if you're importing a lot of data, you'll need to run cron multiple times. You also might run into timeout issues.