Here's the scenario: we have various forms on our website (e.g. Contact Us, Subscribe, etc.). When forms are submitted, unauthenticated webhooks are sent as POST requests to a receiving Apex REST Resource Class. Once received, a resulting Form Submission (Form_Submission__c) is created. Our end goal is to figure out how we can relate Form Submissions to Leads.
While we can tackle this in many ways, we're planning to use Flow's Transform element to instill simplicity, flexibility, and maintainability within the finished product.
Let's design a Record-Triggered Flow that uses the Transform element to fulfill our requirement. We'll need to be conscious of the fact that some of the website forms omit key information that would result in errors when creating Leads. For example, the Subscribe form only asks for an email address.
Here are the Flow Elements in scope:
To start, let's ensure that the incoming Form Submission's Email is populated (this value is used downstream in the Flow):
Next, we'll query any existing Lead with a matching Email:
Check to see if a Lead was received:
If an existing Lead was not found, we'll transform the Form Submission (Form_Submission__c) into a Lead:
Within the Transform element, we need to handle the aforementioned scenario where required fields on a Lead may be excluded from the Webhook's payload.
For the Company and Last Name fields, we'll leverage formulas to handle null values. To add a formula, click on an existing mapping and choose the formula button:
We also need to supplement the Lead data with the appropriate Lead Source value. This is one shortcoming with the current Transform element: it doesn't allow us to populate unmapped fields with formulas.
Create the Lead:
Lastly, we will relate the Form Submission to the appropriate Lead. To do this, we're going to use a formula resource:
Here's the formula used within formulaLeadId:
We're able to rapidly transform data in an aesthetically pleasing manner between flow resources with the Transform element. Anyone that's used ETL software in the past will feel at home with the user interface!