Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Last active September 26, 2019 23:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zuzannamj/765a12020a93ae9056105f7d030b323a to your computer and use it in GitHub Desktop.
%%[
IF RequestParameter("submitted") == true THEN
/* check if lead already exists */
SET @subscriberRows = RetrieveSalesforceObjects(
"Lead",
"Id,Email",
"Email", "=", RequestParameter("email")
)
/* get lead id if lead exists */
IF RowCount(@subscriberRows) > 0 THEN
SET @leadId = Field(Row(@subscriberRows, 1), "Id")
/* update existing lead */
SET @updateRecord = UpdateSingleSalesforceObject(
"Lead", @leadId,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Company", RequestParameter("company")
)
ELSE
/* create a new lead */
SET @leadId = CreateSalesforceObject(
"Lead", 4,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Company", RequestParameter("company"),
"Email", RequestParameter("email")
)
ENDIF
/* add lead to a campaign*/
SET @CampaignMember = CreateSalesforceObject("CampaignMember", 3,
"CampaignId", "7011t0000009Cl1",
"LeadId", @leadId,
"Status", "Sent"
)
/* send a confirmation email */
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_extkey = "43099"
SET @ts_email = RequestParameter("email")
SetObjectProperty(@tsDef, "CustomerKey", @ts_extkey)
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", @ts_email)
SetObjectProperty(@ts_sub, "SubscriberKey", @leadId)
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
]%%
<h2>Thank you for submitting the form, you will get a confirmation email shortly.</h2>
%%[ ELSE ]%%
<table style="padding: 20px;"><tr><td>
<h2>Please fill in the form:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" required=""><br>
<label>Last name: </label><input type="text" name="lastname" required=""><br>
<label>Company: </label><input type="text" name="company" required=""><br>
<label>Email: </label><input type="text" name="email" required=""><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit">
</form>
</td></tr></table>
%%[ ENDIF ]%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment