crmTech/ May 30, 2019/ Cloud, CRM, Salesforce Marketing Cloud/ 0 comments

If Subscriber Key and EmailAddress is same then you can use the below code snippet to unsubscribe.

Input for below code snippet

  1. PubId: External Id of Publication list which will get passed from Email in Unsubscribe link.
  2. emailId : email address which will get passed from Email in Unsubscribe link.
    <!-- Start: Added to Fetch the Subscriber Email Address -->
    SET @emailId = QueryParameter("email")
    SET @PubId = QueryParameter("PubId")
    <!--p> Your Email Address is %%=v(@emailaddr)=%%</p-->
    <!-- End:Added to Fetch the Subscriber Email Address -->
	<script runat=server>
	Purpose : Unsubscribe from the All Publication and All Subscribers List. 
	PubId is nothing but the External Id of Publication list which will get passed from Email in Unsubscribe link.
	 var emailId = Platform.Variable.GetValue('@emailId'); 
	 var listIdArray,listId,listName,listKeylists,myList,status;
	 var unSubList = ""; 
	 var pubId = Platform.Variable.GetValue('@PubId');
	 var data = DataExtension.Init("SSJS_Preferences");
	 var unSubscribeMsg = ""
	 if ((emailId != "null" || emailId != "undefined" || emailId != "") && (Stringify(pubId) != "null" && pubId != ''))
	  listIdArray = pubId.split(',');
	  for(i=0 ; i<listIdArray.length;i++)
	   listId = listIdArray[i];
	   lists = List.Retrieve({Property:"ID",SimpleOperator:"equals",Value:listId});
	   listKey = lists[0].CustomerKey;
	   listName = lists[0].ListName;
	   myList = List.Init(listKey);
	   status = myList.Subscribers.Unsubscribe(emailId);
	   if (status == "OK") 
	     if(unSubList == "")
	       unSubList = listName
	       unSubList = unSubList + "<br>" + listName;
	    if(unSubscribeMsg == "")
	      unSubscribeMsg = "You have not subscribed to publication list..";
	  if(unSubscribeMsg == "")
	   unSubscribeMsg = "You have now succesfully unsubscribed from publication list.";
	  Write("Email Address is NULL");
	if(unSubscribeMsg != "")
	  Write(unSubscribeMsg + "<br>");
Share this Post

About crmTech

Sharad is working from more than 11 years in IT industry. He has giving his technical services in CRM for telecom, automobile, retail, finance industry in Sales, Service and Marketing. He has primary skill in Siebel and Salesforce Marketing Cloud. Apart from this he has worked in Google Cloud, Wordpress blogging, SEO optimization, Short film making, mobile apps creation,logo design creation for his own interest.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.