[SalesForce] Unsubscribing a subscriber from all subscribers using Ampscript

Hi I have a custom unsubscribe page on which i have a checkbox with submit button.

By using these i want to unsubscribe the subscriber from All subscribers. I am using the below code code and getting 500 internal server error.

%%[
    IF not empty(requestParameter("submit")) THEN

//SET @subkey = RequestParameter("Subscriberkey")
   // SET @email = RequestParameter("EmailAddress")

     SET @subkey = "hardcoded for testing"
    SET @email = "hardcoded for testing"

   /* Unsubscribe Subscriber in ET All Subscribers */
SET @sub = CreateObject("Subscriber")
SetObjectProperty(@sub,"SubscriberKey", @subkey)
SetObjectProperty(@sub,"Status", "Unsubscribed")

Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
SetObjectProperty(@save,"SaveAction","UpdateAdd")
SetObjectProperty(@save,"PropertyName","*")
AddObjectArrayItem(@options,"SaveOptions", @save)

/* Here is where we actually update the Subscriber object */
Set @ll_statusCode = InvokeUpdate(@sub, @ll_statusMsg, @update_sub_errorcode, @options)

    IF @ll_statusCode == "OK" THEN
        Redirect("https://pub.s4.exacttarget.com/ts2vjt4qghl")
    ELSE
        RaiseError(@ll_statusMsg, 0, @ll_statusCode, @errorCode)
    ENDIF

ENDIF
]%%

Best Answer

I believe you will want to use LogUnsubEvent instead of Subscriber Object.

Why Use the LogUnsubEvent?
Execute Call Use this call when you create your own landing page or profile center functionality. Previously, you could unsubscribe a subscriber, but you could not create and log the UnsubEvent.

Sample SOAP

<soap-ENV:Body>
    <ExecuteRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
        <Requests>
            <Name>LogUnsubEvent</Name>
            <Parameters>
                <Name>SubscriberID</Name>
                <Value>123456</Value>
            </Parameters>
            <Parameters>
                <Name>SubscriberKey</Name>
                <Value>Key for username@example.com</Value>
            </Parameters>
            <Parameters>
                <Name>EmailAddress</Name>
                <Value>help@example.com</Value>
            </Parameters>
            <Parameters>
                <Name>JobID</Name>
                <Value>18099</Value>
            </Parameters>
            <Parameters>
                <Name>ListID</Name>
                <Value>17914</Value>
            </Parameters>
            <Parameters>
                <Name>BatchID</Name>
                <Value>0</Value>
            </Parameters>
        </Requests>
    </ExecuteRequestMsg>
</SOAP-ENV:Body>
Related Topic