0

When a subscriber clicks on a unsubscribe link from email, they will redirect to a landing page which has confirm and cancel button. When they click on confirm button, I want to retrieve the SF object and update it back. Using the below code, I was able to retrieve the object but the value is not updating back. Basically "Email_c" field should be updated to false when clicked on confirm. Can anyone tell me what is wrong in the below code.

%%[
SET @Subscriberkey = QUERYPARAMETER('sub')
SET @pcname = "Test Journey 1"
SET @Submit = RequestParameter('confirm')

set @rowset = RetrieveSalesforceObjects("Communication_Preference__c","Id,Name,Patient__c","Patient__c","=",@Subscriberkey,"Name","=",@pcname)
IF RowCount(@rowset) == 1 then
set @row = Row(@rowset,1)
set @SFID = Field(@row, "Id")
set @Name = Field(@row, "Name")
set @pid = Field(@row, "Patient__c")
endif

IF @Submit == 'confirm' then
var @result
set @result = UpdateSingleSalesforceObject("Communication_Preference__c",@SFID,"Email__c","False")
endif

]%%


1
  • BTW, if the submission URL is the real URL this seems to me to be exposing detail in this question that you shouldn't since it could be abused by someone wanting to make trouble.
    – Phil W
    Commented Mar 30, 2022 at 6:59

2 Answers 2

1

You need to have a hidden field passing a value to your ampscript on submit (I have added Submitted as a hidden field). It is not enough to set the value of your Submit button. This is how I would build this solution:

%%[
SET @Subscriberkey = QUERYPARAMETER('sub')
SET @pcname = "Test Journey 1"
SET @Submit = RequestParameter('confirm')

set @rowset = RetrieveSalesforceObjects("Communication_Preference__c","Id,Name,Patient__c","Patient__c","=",@Subscriberkey,"Name","=",@pcname)
IF RowCount(@rowset) == 1 then
set @row = Row(@rowset,1)
set @SFID = Field(@row, "Id")
set @Name = Field(@row, "Name")
set @pid = Field(@row, "Patient__c")
endif

if RequestParameter("submitted") == "submitted" then
var @result
set @result = UpdateSingleSalesforceObject("Communication_Preference__c",@SFID,"Email__c","False")
endif

]%%

<form action="https://cloud.email.example.com/page?src=&id=%%=v(@Subscriberkey)=%%&ptname=%%=v(@pcname)=%%" method="post">
<input id="submitted" type="hidden" name="submitted" value="submitted" />
<input type="submit" value="Confirm">
<input type="button" value="Cancel" name="cancel" onclick="window.close()">
</form>
1
  • Hi Lukas, thanks for this updated code. With this now I'm able to retrieve the records (checked by displaying the values on page) but the "Email__c" field value is not getting updated back in SF when clicked on Confirm. Not sure what I'm missing here.
    – user113128
    Commented Mar 30, 2022 at 14:18
-1

Please replace <input type="submit" value="Confirm"> with the below code.

<button type="submit" name="confirm">Confirm</button>

You must log in to answer this question.