We have a cloud page which is used to unsubscribe the records in Marketing cloud. We need to update the "HasOptedOut" field on Contact and a related custom object with a custom field in Sales cloud. This action needs to taken when the email recipient clicks on the Submit button of the landing page.

I know there is a function of Ampscript to update the record in Sales cloud, but I'm not able to implement it as to where and how to use it.

Also, if I need to pass a recordId in the Ampscript of the custom Object which is present in the sendable Data Extention, how can we fetch it in the ampscript and update the custom Object record as well.

2 Answers 2


Firstly, you will need a handler page to write your ampscript to update the relevant fields in Salesforce. Because ampscript works on the load of the cloud page.This handler page will load once the user clicks on Submit. This will contain all the required ampscript and optionally a thankyou/confirmation message to the user. To answer your question, on how to pass the recordid, you need to pass it as a paramter to the handler page and then use RequestParameter to fetch it. Also, you will need additional parameters like email address, subscriber key to be passed in order to unsubscribe withing Marketing Cloud. As a security concern, encode/encrypt these parameters. You can find some sample codes here.


As stated /linked, CloudPagesURL() can be used for encrypting parameters sent from an email, and requestParameter can auto-decrypt parameters encryted through CloudPagesURL().

On your form page, send a post request to a handler page. There, again you can use requestParameter().

more on form / handler: Issue with passing value to data extension from the marketing cloud page

Then, on your handler page you need a LogUnsubEvent call. That will auto-populate "hasoptedOutOfEmail" to true. see also:


Sales Cloud to Marketing Cloud unsubscribe synching

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .