When working in Salesforce, there are many situations that could prompt the need to initiate a data load. Perhaps you need to perform a mass update to a particular field or purge bad data from the system, for example. While the Data Loader and its cousins like DataLoader.io are wonderful tools, they may not always be quite enough to get the job done.
Have you ever wished for more sophisticated data loader functionality? Wouldn’t it be great to have the ability to upload a spreadsheet with only the First Name, Last Name, and Email Address of contact records in order to get the data loader to both find and update those records? By using Platform Events and Data Loader together, these sorts of operations are not only possible — they’re relatively simple!
In this blog post, we’ll discuss how the native feature known as Platform Events can be used to turbocharge your data loads. Then, we’ll describe how we applied this solution to automate a routine data upload for one of our financial services clients.
What are Platform Events in Salesforce?
Salesforce supports what is known as event-driven architecture. Event-driven architecture uses a publish-and-subscribe model to communicate messages between systems, both inside and outside Salesforce. Platform Events are the messages that can be sent back and forth. These ephemeral messages are automatically wiped from the system after 24 hours.
Check out the diagram below:
In the diagram, we see there is an Event Producer, an Event Bus, and an Event Consumer. The Event Bus always lives in Salesforce. The Event Producer can be either inside or outside Salesforce. In the same way, the Event Consumer can also be either inside or outside Salesforce.
In our scenario of using Platform Events to find and update contacts, the Data Loader would act as the Event Producer, publishing lots of messages — or Platform Events — into the Event Bus.
A Salesforce Flow would act as the Event Consumer. Every time it sees one of our Platform Events, it would take a predefined set of actions that we configured beforehand.
To recap, in event-driven architecture, events are produced and consumed by different applications both inside and outside of Salesforce. Platform Events are the messages being sent back and forth between the applications, and the messages only exist for 24 hours.
What are the benefits of using Salesforce Platform Events?
The best thing about Platform Events is that you can define them just as you would a Custom Object. You can name them anything you like, as well as add custom fields for the data points you want the Platform Event message to contain, as shown in the screenshot below:
You can make your Platform Event as broad or as specific as you choose. Above, you can see a custom Platform Event we named “ContactDataLoadEvent” to continue with our previous Contact Data Load scenario. We might then add a custom field for both First Name and Last Name that we could then reference in a Salesforce Flow.
While somewhat beyond the scope of this blog post, Platform Events go far beyond the Data Loader. You can also define Platform Events for External Applications to send and receive messages inside Salesforce. Imagine a printer making an API call into Salesforce with a “Low Ink” Platform Event message. A Salesforce Flow could be subscribed to the “Low Ink” message, ready to create a task for a specific user to go change the ink cartridge.
Can you give an example of Salesforce Platform Events in action?
We recently had a client that received a weekly spreadsheet into an FTP server from their financial custodian. The financial custodian was the source of truth for this data, and the client needed help uploading the data into Salesforce on a weekly basis.
The spreadsheet itself contained multiple tabs, each with numerous columns that mapped to no fewer than three Salesforce objects. Their team’s objective was to update both Person Account fields and Opportunity fields based on this data.
None of the Person Account data had a unique identifier. The only identifier present with each data row was the Account Number of a related Financial Account in Salesforce. The catch was that this number was likely reused across rows of data and therefore wasn’t unique. What to do?
Enter Platform Events!
We defined two Platform Events. One was called AccountInfo and the other was called OpportunityInfo.
Then we built custom fields on our Platform Event to match the columns of the spreadsheet. For Person Account information, this included Name, Phone, Email, and Other Contact Information. We also built a custom field on the Platform Event for the Financial Account Number identifier.
Next, we configured a Salesforce Flow to kick off whenever Salesforce detected one of our custom Platform Events being created. The Salesforce Flow had access to all the Platform Event fields, which allowed for a Get operation to identify the Financial Account based on the Financial Account Number.
Having successfully identified the Financial Account, our Flow could then Get the Person Account associated with the Financial Account using the Primary Owner field (a required lookup field to Accounts).
Finally, having found the Financial Account and Person Account, our Flow could update the Person Account using the information stored in the custom fields of the Platform Event.
So how did we create the Platform Events and trigger the flow? With the Data Loader!
After logging into Data Loader, we chose the “Insert” operation, and then selected our AccountInfo__e event from the list:
Then we mapped our spreadsheet columns to our Platform Event fields:
And finally, we inserted our data!
Our Flow detected our incoming Platform Event. We used the Financial Account Number to identify the Financial Account, then used the Primary Owner field to identify the Person Account to update. We did it!
We followed the same steps with the client’s Opportunity data to successfully update Opportunities in Salesforce.
Best of all, the client’s team was able to automate the data load — meaning the entire process became fully automated.
In summary, Platform Events are a powerful tool. With just a few steps, it’s easy to leverage them in conjunction with the Data Loader to perform complex database updates in Salesforce.
To learn more about these and other intuitive integrations, contact us today at firstname.lastname@example.org.
Author Credit: Nick Frates, Consultant at ShellBlack