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
basha skbasha sk 

How to redirect to the previous visualforce page from current visualforce page (like back button)?

How to redirect previous visualforce page from current visualforce page?

Hi Everyone,

 First of all here i'm having two visualforce pages
 
 1.Webinar_Details Page
 2.MappingLeadPage
 
 webinar_details page is a record details page it displays all the details of one particular record.
 In this page i'm having a button calles "Mapping Lead" by clicking the button it redirects to the
 "MappingLeadPage" visualforce page.after mapping the fields i'm saving the mapping and redirects to the previous record
 details page.
 
 here for redirecting i need the previous record id.how can i get the previous record id for redirecting
 
 Webinar_Details Page
 --------------------
 <apex:page standardController="Webinar__c" tabstyle="Adobe_Webinars__tab" sidebar="false" extensions="RedirectPage">
    
    <apex:form >   
     <apex:pageBlock title="Adobe Connect Integration with Salesforce">
         <center>         
           <apex:commandButton value="Register" action="{!doRegistrationForm}"/>     
         </center><br/><br/>
         <apex:pageBlockSection title="{!Webinar__c.Name} Details">
            <apex:outputField value="{!Webinar__c.Name}"/>      
            <apex:inlineEditSupport event="ondblClick" /><br/>                    
         </apex:pageBlockSection><br/>         
    </apex:pageBlock>           
          <apex:pageBlock >
            <apex:pageBlockTable value="{!wrapperAccountList}" var="w" id="table" title="All Accounts">
                 <apex:column value="{!w.acc.Login__c}"></apex:column>
                 <apex:inlineEditSupport event="ondblClick" />
                 <apex:column value="{!w.acc.isLead__c}"></apex:column>                                
            </apex:pageBlockTable>
        </apex:pageBlock>
               
         <center>
              <apex:commandButton id="leadcreate1" value="Lead Mapping" action="{!doMappingPage}"/>
          </center><br/>   
    </apex:pageBlock>      
 </apex:form>         
</apex:page>

extension:
-----------

 public class RedirectPage{
 
        public PageReference doMappingPage(){            
        PageReference parentPage = new PageReference('/apex/MappingLeadPage');
        parentPage.setRedirect(true);
        return parentPage;
  }
 
}

MappingLeadPage
----------------
<apex:page standardController="Lead" extensions="MappingLead1">    
  <apex:form >  
    <apex:pageBlock title="Lead Mapping" >             
      <apex:pageBlockSection >       
        <apex:pageBlock >            
           <apex:pageBlockSection >          
                   Webinar Attendee Name  <apex:inputField value="{!Lead.LeadFields__c}"/><br/>  
                   Webinar Attendee Email <apex:inputField value="{!Lead.Lead_Fields1__c}"/><br/>
                   Webinar Attendee Company  <apex:inputField value="{!Lead.Lead_Fields2__c}"/><br/>  
               Webinar Attende Mobile Number <apex:inputField value="{!Lead.Lead_Fields7__c}"/><br/><br/>
                  <!--   <apex:outputLink value="{!URLFOR($Page.Webinar_Details,w.acc.Id,[id=w.acc.Id])}">{!w.acc.name}</apex:outputLink>    -->         
            
         </apex:pageBlockSection>
            <apex:commandButton id="saveBtn" value="Save Mapping" action="{!processButtonClick}" style="margin-left:-2%"/>                                          
               <apex:commandButton id="saveBtn1" value="Previous Page" action="{!goBack}" style="margin-left:30%"/>                                          
            <apex:pageBlockButtons >
            </apex:pageBlockButtons>
       </apex:pageBlock>   
     </apex:pageBlockSection>     
   </apex:pageBlock>                
  </apex:form>
</apex:page>


extension
------------
public with sharing class MappingLead1  {
    public Lead login;
    private final ApexPages.StandardController controller;                  
    public MappingLead1(ApexPages.StandardController controller){       
        this.login= (Lead)controller.getRecord();  
    }

    public PageReference goBack(){
    PageReference pg = new PageReference('/apex/Webinar_Details');
    pg.setRedirect(true);
    return pg;
  }
}

from the MappingLeadPage page by clicking the "Previous Page" button how i redirected to the Webinar_Details Page vf page.

Please anybody help i'm trying this logic from yesterday

Thanks In Advance

 
Prashant Pandey07Prashant Pandey07
You may use below code to redirect to the previous page..
 
public string previouspage = ApexPages.currentPage().getParameters().get('retURL');   

public PageReference previous(){
        PageReference pg = new PageReference(previouspage);
        pg.setRedirect(true);
        return pg;
    }

--
Thanks,
Prashant
basha skbasha sk
@Prasanth Thanks for giving the response .I tries this then i got the error like Argument 1 cannot be null Error is in expression '{!previous}' in component in page adobeeventregistrationform: Class.LightiningEd.RedirectPage.previous: line 39, column 1 Thanks
basha skbasha sk
@Prasanth herew what is the value of retURL?
Prashant Pandey07Prashant Pandey07

@basha
its a url parameter when you want to redirect the user to when he clicks the previous button.

Check in your url and see if there is any retURL.

Are you using lightning or Salesforce classic?

--
Thanks,
Prashant

 
basha skbasha sk
@Prasanth I'm using salesforce classic. When i click the previous button nothing is change in retURL.it stay on the same page
Prashant Pandey07Prashant Pandey07
@Basha,

Ok..i thought you have retUrl in your VF..no worry.. you just need to get the current page id from url and then redirect to MappingLeadPage.

Get the current page id like
Public String ids=Apexpages.currentPage().getParameters().get('id');
then pass this id in the doMappingPage method.
 
public PageReference doMappingPage(){
    PageReference pg = new PageReference('/apex/Webinar_Details/id='+ids);
    pg.setRedirect(true);
    return pg;
  }
}

Now you will see there MappingLeadPage with the previous record.

again in MappingLead1 class get the id as above shown. and now your goback method looks like below.
 
public PageReference goBack(){
    PageReference pg = new PageReference('/'+ids);
    pg.setRedirect(true);
    return pg;
  }

--
Thanks,
Prashant
 
basha skbasha sk
@Prasanth thanks for giving the response i'm using the methods like as you suggested Redirect class i'm using doMappingPage and goBack() in MappingLead1 class by clicking the goback method i got error called URL NO longer exists.please check it once and 

public PageReference doMappingPage(){
    PageReference pg = new PageReference('/apex/MappingLeadPage/id='+ids);
    pg.setRedirect(true);
    return pg;
  }
}

in the above if i'm using like this oi got another error called  
Id value a0N0K00001HzZ67 is not valid for the Lead standard controller    please check it once i'm using two different standrd conrollers in two pages .Thanks
Prashant Pandey07Prashant Pandey07
@Basha,

in goback method I didn't add the page name..you may add this '/apex/Webinar_Details'

Can you send me full class...and is Webinar_Details page is overridden on view button.

--
Thanks,
Prashant
basha skbasha sk
@Prasanth please check the below class Webinar Details Page :