New to this blog series? Be sure to start by reading Marketing Cloud Lead Submission (Part 1): How to Build Your Foundation.
Now once you have your data and variables defined from your submission, you can process your data to Salesforce. If you are creating a new Lead or Contact, the process is the same (only a single variables changes in the submit function). In our example, we are passing an accountID variable, which will be used to determine whether or not the user is a new Lead or existing Contact that we will add to our email campaign.
Example: Where to Start
To start off, let’s get into our pre-population script portion of our AMPScript. Initially, we check if our @Submit variable is not equal to “Success”, which will return empty on our initial page load. Entering our IF statement based on this criteria, we do a Data Extension LookUpRows using the @email variable, which can be passed through query string to our landing page. Accessing the Data Extension gives us great flexibility in personalization options since we could display anything from that extension on our page. For now, we are determining a new Lead or Contact via Data Extension, if they have an existing record. If the @email variable matches an Email field in the Data Extension, the @accountID variable is populated; if not, the variable is left blank.
= Form Submission Lead/Contact Creation =
IF @Submit != “Success” THEN
= Pre-Populate Based on Email =
VAR @rows, @row, @rowCount
SET @rows = LookupRows(‘ENT.Data Extension Name’, ‘Email’, @email)
SET @rowCount = RowCount(@rows)
IF @rowCount > 0 THEN
SET @row = Row(@rows,1)
SET @accountID = Field(@row, “Id”)
The Manufacturer’s Guide to Marketing Through Partner Enablement in 2021
Learn how partnerships allow manufacturers to scale revenue growth beyond what’s possible with direct sales alone.
Get the Guide
At this point, the user has filled out the form and hit the submit button. Our @Submit variable will now be populated with “Success,” moving it to the second part of our IF statement for processing. Right away, we check if the user has an @accountID, which determines our path through the following submission statements. NOTE: We are not looking to UpdateSingleSalesforceObject in this example. We’re simply creating new entries to a Campaign.
Quick Breakdown of Variables
Variables break down within the CreateSalesforceObject as such:
- ‘Lead/Contact’ = Determines which type of object is submitted to Salesforce
- 6 = Number of variables to add to submission, minimum of required fields, maximum of defined in function
- ‘Salesforce ObjectID’, @variable
I separate my submit variables into two sections, required and optional. This way I know I have my required variables covered when they’re submitted, and if I happen to get an error, I can systematically go through the optional variables to find the problem submit. This is where having access to the Salesforce instance as a developer is critical, so that you can double-check your work and ensure proper field mapping.
= Lead Creation =
IF EMPTY(@accountID) THEN
SET @leadID = CreateSalesforceObject(‘Lead’, 6,
‘RecordTypeId’, ’18-Digit Record Type ID’,
= Contact Creation =
SET @contactID = CreateSalesforceObject(‘Contact’, 11,
‘RecordTypeID’, ’18-Digit Record Type ID’,
Once the @leadID or @contactID are created, we set another CreateSalesforceObject function, which is set to create the Campaign Member connection using either of those variables. The @campaignID is manually defined as a hidden field in our form, which is passed through url upon submit. After all those functions pass, our IF statements are completed and page Redirects to our defined thank-you page.
This example is a simple, easy way to utilize Data Extension personalization and AMPScript to submit forms to Salesforce within Marketing Cloud. With this foundation in place, we are able to take advantage of the customization options available through Marketing Cloud to expand solutions for clients.
We’re Here to Help
Watch for more articles on AMPScript and Marketing Cloud customization in the future. And in the meantime, contact our team with any questions.