Final - Salesforcer Package
Introduction to salesforcer Package
R is a widely used progamming platform and Salesforce is a widely used CRM. Why not combine the two and make magic? Often times, reporting in Salesforce can be difficult and in most cases you have to pull down a csv file, manipulate it match up IDs and upload back up to Salesforce. That said, Salesforce provides open APIs for users so we can connect to. So in this vingette we will be connecting to our dev org, we will pull down data, manipulate it, and update Salesforce.
Current Use Case
One of the most common issues in Salesforce and Salesforce management is data cleanliness and data accuracy. Admins, like myself, spend a lot of time putting safeguards in place but where there is a will, there’s a way and our Sales team will find some way to create duplicate records in the system.
So in this example, I’m going to use R to fetch records from Salesforce, finding matches and merge the records in Salesforce while not losing information.
Install the library(salesforcer)
Step 1:Use OAuth to sign in to your Salesforce instance:
Using OAuth 2.0 authentication sf_auth()
Using Basic Username-Password authentication sf_auth(username = “THIS WILL BE YOUR EMAIL”, password = “ENTER PASSWORD TO YOUR DEV ORG”, security_token = “ENTER YOUR SECURITY TOKEN”)
To find your security token, please click here:https://help.salesforce.com/articleView?id=user_security_token.htm&type=5
Let’s get to fun part: Find Duplicates in the system:
Requirements as noted in CRAN:
master_id character; a Salesforce generated Id that identifies the master record, which is the record to which the victim records will be merged into
victim_ids character; one or two Salesforce Ids of records to be merged into the master record. Up to three records can be merged in a single request, including the master record. This limit is the same as the limit enforced by the Salesforce user interface. To merge more than 3 records, successively merge records by running sf_merge repeatedly.
object_name character; the name of one Salesforce objects that the function is operating against (e.g. “Account”, “Contact”, "CustomObject__c")
master_fields named vector; a vector of field names and values to supersede the master record values. Otherwise, the field values on the master record will prevail.
api_type character; one of “REST”, “SOAP”, “Bulk 1.0”, “Bulk 2.0”, or “Chatter” indicating which API to use when making the request control list; a list of parameters for controlling the behavior of the API call being used.
For more information of what parameters are available look at the documentation for sf_control … arguments passed to sf_control
Step 2:
Enable Contact Duplicate rules in Salesforce. Navigate to Setup in Salesforce then navigate to Duplicate Rules and click on Contact Duplicate Rules.
Next, for monitoring purposes and to check your work, create a custom report type in Salesforce.
Step 3: Decide what you would like to match on.
In this case we will match on email, but use could match on fields such as ID or First Name/Last Name.
# find them as dupes
dupes_found <- sf_find_duplicates(search_criteria = list(Email = "dailey@thathertonfuels.com"), object_name = "Contact")## Using Contact rules: Standard_Rule_for_Contacts_with_Duplicate_Leads
This is how the duplicates will look like in Salesforce:
Step 4: Merge records:
When converting records, select the master_fields on the record. In Salesforce, when you have three matching records, you need to identify the key fields you’d like to “win” which in this case would be the record where website = “salesforcer.com.”
merge_summary <- sf_merge(master_id = dupes_found$Id[1],
victim_ids = dupes_found$Id[2],
object_name = "Contact",
master_fields = c("Website__c" = "salesforcer.com"))
merge_summary## # A tibble: 1 x 5
## id success mergedRecordIds updatedRelatedIds errors
## <chr> <lgl> <lgl> <lgl> <list>
## 1 00Qf4000004mbHmEAI FALSE NA NA <named list [2]>
*Example shows False as this scenario has already run against these IDs.
For more resources: CRAN: https://cran.r-project.org/web/packages/salesforcer/index.html
Keep your data clean and use Salesforcer!
A work by Elyse King