So in the last article, Customize Syncing Between Drupal Commerce and Salesforce – Part 1, we covered the initial checks to make sure we were targeting the right entities and also making sure they contain the right values before moving forward with our syncing to Salesforce. Now we can focus on the actual syncing with Salesforce.
Customize Syncing Between Drupal Commerce and Salesforce – Part 1
The Salesforce Suite module created to connect Drupal to Salesforce is an amazing tool and can help you get up and running with syncing your content right away. It allows you to create individual mappings between Drupal entities and Salesforce objects and have them triggered by CRUD and can be controlled using cron jobs.
Though the Salesforce Suite does not offer the ability to check for existing records along the way and often results in hundreds if not thousands of duplicates. This was a major issue for me since the site I am working with uses Commerce, Commerce Registration, and Entity Registration to allow customers to register and pay for events and courses. We needed this information to be sent to Salesforce and check along the way to see if the registrant(s) were new or if they already existed, and the same goes for their billing information.
But how? The Salesforce Suite only provides the ability of setting a single key field which limits your ability to find a match based on only 1 matching field. This can become a big issue since people share the same names or same email accounts, so you would want to take advantage of looking up records based on a series of criteria. So I was able to utilize the Salesforce API and the provided Salesforce Suite’s hooks to write the checks and take control of the entire import process myself. Note that the following code examples code probably be improved since I am fairly new to building custom modules in Drupal and also fairly new to PHP. Also the following is describing how to connect Commerce and Commerce Registration to Salesforce, so in your case you may need to skip some of this and move on to Part 2 if you are only looking for some simple examples of checking and pushing/updating records.