7

We have a VF page form ( web to lead ) in which after clicking the submit button it goes to another VF page ( having Thank you message). But when we click browser back button the form is getting resubmitted and duplicate records are getting created. We are using standard Lead controller in the VF page. We have set cache="false".

Is there additional thing I have to do as this problem is very new to us. In past there was no such problem.

Apex

public class RedirectPage { 
    PageReference pr1; 
    PageReference pr2; 
    public PageReference GoToPage(){ 
        try { 
            PageReference cpage = new PageReference('/apex/confirmationPage'); 
            cpage.setRedirect(true);
            pr1 = cpage; 
        } catch (Exception e) {

        } 
        return pr1;
    } 
    public PageReference GetRedir() { 
        try { 
            PageReference telecallerPage = new PageReference('/apex/Proposal_Registration'); 
            telecallerPage.setRedirect(true); 
            pr2 = telecallerPage; 
        } catch (Exception e) {

        } 
        return pr2;
    } 
} 

VisualForce

<apex:page controller="RedirectPage" action="{!GoToPage}" />
  • 1
    Can you post some code from the controller? I want to see if you have any actions on the page itself and what is happening inside the constructor. – subodhbahl Sep 13 '13 at 16:29
  • Please post some code so we can try to help identify the issue – Chris Duncombe Sep 16 '13 at 13:52
  • Sorry for late reply: Now I have added a blank page in between form submit button and confirmation page( last page). What I want to do is the when user click submit button it will goes to intermediate page and from there it gets automatically directed to last page (in apex:page added action tag to do this). My idea was that whenever a user click browser back button in last page it never goes back to form page and user always gets redirected to last page. Unfortunately the form is still getting resubmitted even after coming back to last page.... contd.. – Rohit Sep 27 '13 at 5:47
  • code:public class RedirectPage{ PageReference pr1; PageReference pr2; public PageReference GoToPage(){ try{ PageReference cpage = new PageReference('/apex/confirmationPage'); cpage.setRedirect(true); pr1 = cpage; }catch(Exception e){} return pr1;} public PageReference GetRedir() { try{ PageReference telecallerPage = new PageReference('/apex/Proposal_Registration'); telecallerPage.setRedirect(true); pr2 = telecallerPage; }catch(Exception e){} return pr2;} } 2nd Page: <apex:page controller="RedirectPage" action="{!GoToPage}" >.. contd... – Rohit Sep 27 '13 at 5:53
  • can anybody guide how to submit the code as the above code is looking very clumsy. Not able to submit in correct format. I also have limit in character. – Rohit Sep 27 '13 at 5:57
1

You can take help from the below code:

(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/stealingyourhistory");
history.pushState(null, document.title, location.pathname);

window.addEventListener("popstate", function() {
  if(location.hash === "#!/stealingyourhistory") {
        history.replaceState(null, document.title, location.pathname);
        setTimeout(function(){
          location.replace("http://www.xyz.com/");
        },0);
  }
}, false);
}(window, location));

this will override your back button and redirect you to the page given in location .replace(). Let me know if this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.