Skip to main content
3 of 3
edited tags
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

profile center ampscript not working

I build a profile center using ampscript and cloudpage, I tried to update all subscribers status use below code but it did not update the subscriber's status at sfmc:


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)