You’re most likely getting a 500 because the parameters are not passed correctly.
Try creating a test list and doing an actual send to that list.
Here are three things to try:
1. Make sure all parameters are passed.
As Cameron noted, you have a parameter in the processing page which is not getting passed, and this is most likely the source of the problem:
RequestParameter("Subaction")
To make it work, you need to include the parameter in the link in your first page:
%%=CloudPagesURL(254,"Subaction","unsub")=%%
Above is just hardcoded, so if they have a choice of subscribing/unsubscribing, pass the real parameter.
If they only have a choice to unsubscribe, I would strip this completely from the processing page:
/* Log Unsub Event */
IF RequestParameter("Subaction") == 'unsub' THEN
/* Update ET unsub and log it for tracking */
And strip the ENDIF
at the end.
2. If you’re using the CloudPagesURL function, you don’t need to pass the personalization strings separately.
Change to the following in your processing page:
SET @SfContactId = RequestParameter("_subscriberkey")
SET @EmailAddress = RequestParameter("emailaddr")
You can try displaying the values on the page to see if they are passed correctly:
@SfContactId: %%=v(@SfContactId)=%% <br>
@EmailAddress: %%=v(@EmailAddress)=%%
3. Debug the Salesforce functions.
One last thing you can do is wrapping your script in a try/catch statement, to see if the Salesforce functions are causing any issues.
Best Answer
I'd suggest adding some debugging statements to see what's not getting populated before you add in your
UpdateSingleSalesforceObject()
function:Update
You probably should be using QueryParameter() instead of RequestParameter() if you're just retrieving URL parameters by name: