1

I have an email that I'm sending to contacts to request for them to click on a button if they would like to be subscribed to our new newsletter.

When a person clicks, it will take them to a CloudPage (landing page) created in Marketing Cloud that simply says "thank you". Behind the scenes, I want to update a checkbox in Salesforce to be true using AMPscript's UpdateSingleSalesforceObject.

Below is the snippet I'm using, however, it breaks my landing page.

%%[UpdateSingleSalesforceObject('Contact','%%SubscriberKey%%','EG_in_Brief__c','true') ]%%

What am I doing wrong? Thank you!

2

I'd suggest retrieving the Subscriber Key with AttributeValue() and ensuring it has a value before updating your SF object.

%%[

var @sk, @result
set @sk = AttributeValue("SubscriberKey")

if not empty(@sk) then

 set @result =  UpdateSingleSalesforceObject('Contact',@sk,'EG_in_Brief__c','true')

endif 

]%%
Thanks!
<br>(result: %%=v(@result)=%%)

Double-percent notation is only necessary/valid outside of AMPScript blocks (%%[ ]%%).

Reference

  • Thank you! I copied your code into my HTML and I'm not seeing the checkbox in Salesforce being updated on the Contact I sent the email to. Also, the result: is blank when visiting the page. Perhaps, am I missing a prerequisite? – Watson Oct 31 '17 at 22:11
  • Does the custom field, EG_in_Brief__c, need to be mapped as a data extension in Marketing Cloud? – Watson Oct 31 '17 at 22:20
  • Nope, but Marketing Cloud Connect needs to be configured. – Adam Spriggs Nov 1 '17 at 0:58
  • Thank you. I confirmed it's working properly by checking the status of a Marketing Cloud Connector Integration How do I debug AMPscript? – Watson Nov 2 '17 at 10:43
  • Have you tried checking if the @sk variable has a value using %%=v(@sk)=%%. See if it's giving you what you expect. Put display statements after every statement to confirm the code is doing what is needed. – Rajdeep Singh Nov 5 '17 at 2:28
1

I was able to make this work by:

1) Point the button's URL inside my email to my landing page key using: %%=RedirectTo(CloudPagesURL(1077))=%% Using this in my email allows me to reference the subscriber key from the email on the landing page as _subscriberkey

2) Ensure subscribers on the target list had the 18 digit Contact ID listed as Subscriber Key within Marketing Cloud

3) Update the AMPscript, remove AttributeValue() and use the passed in subscriberkey:

%%[

VAR @sk, @result
SET @sk = _subscriberkey

if not empty(@sk) then

 set @result =  UpdateSingleSalesforceObject('Contact',@sk,'EG_in_Brief__c','true')

endif 

]%%

AttributeValue() will not work because its function is to grab a subscriber attribute. On a landing page, subscriber attributes aren't set unless they've been passed in through a link.

References: CloudPagesURL

  • You don't need the redirectto() function in point #1 -- CloudpagesURL() passes the send context already. – Adam Spriggs Nov 8 '17 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.