1

I have a cloudpages custom unsubscribe page. It has LogUnSubEvent (AMPScript) which on unsubscribe updates the Subscriber status to Unsubscribed and sets HasOptedOutOfEmail flag to true on Salesforce Contact record.

Now if on this custom Cloud page a person re-subscribes... How do I update Salesforce Contact record to set the HasOptedOutOfEmail flag to false. Salesforce support confirmed today that UpdateSingleSalesforceObject is not supported on CLoudPages due to TLS. So that is not an option (It throws 500 Internal Server error).

What are my other alternatives? Please help ASAP.

3

I have to agree with Eliot here. I am using the UpdateSingleSalesforceObject() function with cloudpages and have no issues. I also agree that the 500 error is not very helpful. I would suggest running the AMPScript code within a Server-side JavaScript block in order to catch and output the error. It might help to troubleshoot your issue further.

<script runat='server'>
  Platform.Load('Core','1.1.1');
  try {
</script>  

%%[
var @Id, @HasOptedOutOfEmail, @updateEmail
set @Id = '0019000000nI8zT'
set @HasOptedOutOfEmail = false
set @updateEmail = UpdateSingleSalesforceObject('Account',@Id,'PersonHasOptedOutOfEmail', @HasOptedOutOfEmail)
]%%

<script runat='server'>
  } 
  catch(e) {
    write(Stringify(e));
  }
</script>  
3
  • I didn't know that you could use this approach to display AMPscript debug information. However, unfortunately it does not appear to work in CloudPages. I wish it did! If I use the code above it works fine, but if I update the @Id value to an Id that does not exist, I get the dreaded 500 - Internal server error message. Aug 12 '16 at 21:00
  • It'll work if you put all of the code in a Content Area and include it with a ContentAreaByName() function. We tend to manage all of our CloudPage code in Content Areas since you can update them with the API. Aug 13 '16 at 11:43
  • Hi Adam, I didn't know that. However I've tried what you suggested and it still does not work; if my AMPscript is invalid, I still get the 500 error on my CloudPage. Here is the code on my CloudPage and my Content Area (with deliberately incorrect AMPscript). Can you check to see why this does not return debug information? Aug 16 '16 at 22:36
1

Hmmm, that's interesting. I use the UpdateSingleSalesforceObject() AMPscript function on CloudPages without any problems.

Note sure what they mean by "TLS". Do you have a SSL certificate on the domain attached to your CloudPage? I mean, does your CloudPage URL start with https://?

If so, then perhaps it's a limitation with SSL certificates on CloudPages but I can't see why when you consider that this is a server-side script.

Firstly I would double-check that there's nothing wrong with your AMPscript. That pesky 500 error isn't helpful in CloudPages, but you can get some helpful debug information if you test your code in an email. Try the following:

  1. Create a new text email
  2. Paste the code below (edit as required)
  3. Save
  4. Click Send Preview
  5. Select All Subscribers
  6. Select any subscriber
  7. Click Generate Preview
  8. Check the record in Salesforce to confirm that it's been updated.

If that works, then try the same code on a CloudPage.

%%[
var @Id, @HasOptedOutOfEmail, @updateEmail
set @Id = '0019000000nI8zT' /* replace with the Contact you are testing */
set @HasOptedOutOfEmail = false
set @updateEmail = UpdateSingleSalesforceObject('Contact',@Id,'HasOptedOutOfEmail', @HasOptedOutOfEmail)
]%

Person Account Sidenote

With Person Accounts, there are a couple of minor differences as you use the Account object instead of the Contact object and the field is named PersonHasOptedOutOfEmail instead of HasOptedOutOfEmail, but it's essentially the same. Here's the code I'm using with a Person Account:

%%[
var @Id, @HasOptedOutOfEmail, @updateEmail
set @Id = '0019000000nI8zT'
set @HasOptedOutOfEmail = false
set @updateEmail = UpdateSingleSalesforceObject('Account',@Id,'PersonHasOptedOutOfEmail', @HasOptedOutOfEmail)
]%%

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.