Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Last active January 14, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zuzannamj/ecf38a80640ed12b60c3a9b88e91029c to your computer and use it in GitHub Desktop.
Save zuzannamj/ecf38a80640ed12b60c3a9b88e91029c to your computer and use it in GitHub Desktop.
IF RequestParameter("submitted") == true AND RequestParameter("unsub") == true THEN
/* update contact in Sales Cloud */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"Newsletter__c", "false",
"Events__c", "false",
"Offers__c", "false",
"HasOptedOutOfEmail", "true"
)
/* log unsubscribe event to mark as unsubscribed in All Subscribers */
SET @reason = "Unsubscribed through custom subscription center"
SET @lue = CreateObject("ExecuteRequest")
SETObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "SubscriberKey")
SETObjectProperty(@lue_prop, "Value", @contactId)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "Reason")
SETObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment