function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priyesh Misquith 12Priyesh Misquith 12 

vf page rendering based on url parameter and action

I have the following code which based on the url parameter contact id and the unSubsEmail(which is subscibe and unsubscribe) value true or false when user click on subscribe or unsubscrib in mail
as per the current scenario on click of subscribe or Unsubscribe the directly the action is called and the message is displayed directly.
now my requirement is to put the confirmation message for unsubscribe scenario like "are you sure ? " displayed and when user clicks on OK button the message "Congratulations, You have Successfully {!subscriptionText}" should be displayed
for subscibe directly the message need to be displayed "Congratulations, You have Successfully {!subscriptionText}" there will be no  confirmation message.

Please let me know how this can be achived.
 
<apex:page sidebar="false" showHeader="false" controller="SubscribeUnsubscription" action="{!SubUnSub}" >
  <body style="margin:0px; padding:0px; background-color:#f1f1f1;">
<div id="SubUnSub" style="display:{!if(unsubscribeemail,"block","none")};">
    <p style="font-family: Open Sans, sans-serif !important; margin-left: 20% !important; margin-top: 5% !important; font-size: large;">
        <br/>
            Congratulations, You have Successfully {!subscriptionText} <br/><br/>
    </p>
</div></body>
</apex:page>



global Class SubscribeUnsubscription
{  
    global Boolean      unsubscribeemail {get; set;}
    global String       	ConEmail {get; set;} 
    global String       subscriptionText {get; set;}
    global String       ConId {get; set;}
    
 
    global SubscribeUnsubscription()
    { 
                  
    }
    
 
    global void SubUnSub()
    {
        ConId = ApexPages.currentPage().getParameters().get('ConId');
        

        if(String.isBlank(ApexPages.currentPage().getParameters().get('unSubsEmail')))
        {
            unsubscribeemail = false;
        }
        else
        {
            unsubscribeemail = Boolean.valueOf(ApexPages.currentPage().getParameters().get('unSubsEmail')); 
        }

        if(!String.isEmpty(ConId))
        {
            contact con = [ SELECT  Id, Email, Unsubscribe__c FROM  Contact WHERE  Id = :ConId ];

            if(unsubscribeemail && !con.Unsubscribe__c)
            {   
                con.Unsubscribe__c = true;
                update con;
                subscriptionText = 'Unsubscribed';
            }
            else if(!unsubscribeemail && con.Unsubscribe__c)
            {          
                con.Unsubscribe__c = false;
                update con;
                subscriptionText = 'Subscribed';
                unsubscribeemail = true;
            }
            else if(!unsubscribeemail && !con.Unsubscribe__c)
            {          
                subscriptionText = 'Subscribed';
                unsubscribeemail = true;
            }
            else if(unsubscribeemail && con.Unsubscribe__c)
            {          
                subscriptionText = 'Unsubscribed';
                
            }
            
        }

    }
}

 
Dushyant SonwarDushyant Sonwar
Hi Priyesh,

There is already an appexchange app by salesforce labs that will save your time and effort of custom development.

https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FMkfNUAT

https://appexchange.salesforce.com/appxListingDetail?listingId=a0N300000016YDZEA2


Hope this helps!