Avoid changing Visualforce page URL

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2














The Visualforce page has



<apex:commandButton action="!submit" value="Submit"/>


The submit method returns void.



public void submit()


Now the page has certain URL parameters, the submit method correctly possesses them and works as expected except that while returning, it deletes URL parameters.



The URL '/apex/pageName?var1=abcd&var2=pqrs' becomes '/apex/pageName'. The parameters are gone. Problem with this is when user refreshes the page, it doesn't work as expected as url parameters are not there.



When I change submit method to return PageReference of current page, it rewrites URL with URL parameters + view state which looks unclean.



 PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
pageRef.setRedirect(true);
return pageRef;


How can we ensure that URL parameters are not changed.










share|improve this question


























    2














    The Visualforce page has



    <apex:commandButton action="!submit" value="Submit"/>


    The submit method returns void.



    public void submit()


    Now the page has certain URL parameters, the submit method correctly possesses them and works as expected except that while returning, it deletes URL parameters.



    The URL '/apex/pageName?var1=abcd&var2=pqrs' becomes '/apex/pageName'. The parameters are gone. Problem with this is when user refreshes the page, it doesn't work as expected as url parameters are not there.



    When I change submit method to return PageReference of current page, it rewrites URL with URL parameters + view state which looks unclean.



     PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
    pageRef.setRedirect(true);
    return pageRef;


    How can we ensure that URL parameters are not changed.










    share|improve this question
























      2












      2








      2







      The Visualforce page has



      <apex:commandButton action="!submit" value="Submit"/>


      The submit method returns void.



      public void submit()


      Now the page has certain URL parameters, the submit method correctly possesses them and works as expected except that while returning, it deletes URL parameters.



      The URL '/apex/pageName?var1=abcd&var2=pqrs' becomes '/apex/pageName'. The parameters are gone. Problem with this is when user refreshes the page, it doesn't work as expected as url parameters are not there.



      When I change submit method to return PageReference of current page, it rewrites URL with URL parameters + view state which looks unclean.



       PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
      pageRef.setRedirect(true);
      return pageRef;


      How can we ensure that URL parameters are not changed.










      share|improve this question













      The Visualforce page has



      <apex:commandButton action="!submit" value="Submit"/>


      The submit method returns void.



      public void submit()


      Now the page has certain URL parameters, the submit method correctly possesses them and works as expected except that while returning, it deletes URL parameters.



      The URL '/apex/pageName?var1=abcd&var2=pqrs' becomes '/apex/pageName'. The parameters are gone. Problem with this is when user refreshes the page, it doesn't work as expected as url parameters are not there.



      When I change submit method to return PageReference of current page, it rewrites URL with URL parameters + view state which looks unclean.



       PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
      pageRef.setRedirect(true);
      return pageRef;


      How can we ensure that URL parameters are not changed.







      visualforce






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 19 '18 at 10:34









      Ganesh Bhosle

      1,3041935




      1,3041935




















          2 Answers
          2






          active

          oldest

          votes


















          3














          If you are not redirecting the page then you should use rerender attribute.



          <apex:commandButton action="!submit" value="Submit" rerender ="form"/>


          Just give outer form the Id and then rerender it instead of refreshing the complete page,. It will not remove URL parameters.






          share|improve this answer




























            0














            From Salesforce Docs:




            When a redirect occurs the controller clears the context state.
            Consequently we need to reset the query string parameter in the
            PageReference's parameter map.




            Thus your code will be.



            PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
            pageRef.setRedirect(true);
            pageRef.getParameters().put('var1', ApexPages.currentPage().getParameters().get('var1'));
            pageRef.getParameters().put('var2', ApexPages.currentPage().getParameters().get('var2'));
            return pageRef;


            Src: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_navigation_methods.htm






            share|improve this answer
















            • 1




              The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
              – sfdcfox
              Dec 19 '18 at 11:35










            • But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
              – Pranay Jaiswal
              Dec 19 '18 at 11:38






            • 2




              Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
              – sfdcfox
              Dec 19 '18 at 11:43










            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244155%2favoid-changing-visualforce-page-url%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            If you are not redirecting the page then you should use rerender attribute.



            <apex:commandButton action="!submit" value="Submit" rerender ="form"/>


            Just give outer form the Id and then rerender it instead of refreshing the complete page,. It will not remove URL parameters.






            share|improve this answer

























              3














              If you are not redirecting the page then you should use rerender attribute.



              <apex:commandButton action="!submit" value="Submit" rerender ="form"/>


              Just give outer form the Id and then rerender it instead of refreshing the complete page,. It will not remove URL parameters.






              share|improve this answer























                3












                3








                3






                If you are not redirecting the page then you should use rerender attribute.



                <apex:commandButton action="!submit" value="Submit" rerender ="form"/>


                Just give outer form the Id and then rerender it instead of refreshing the complete page,. It will not remove URL parameters.






                share|improve this answer












                If you are not redirecting the page then you should use rerender attribute.



                <apex:commandButton action="!submit" value="Submit" rerender ="form"/>


                Just give outer form the Id and then rerender it instead of refreshing the complete page,. It will not remove URL parameters.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 19 '18 at 10:58









                Tushar Sharma

                24.7k52148




                24.7k52148























                    0














                    From Salesforce Docs:




                    When a redirect occurs the controller clears the context state.
                    Consequently we need to reset the query string parameter in the
                    PageReference's parameter map.




                    Thus your code will be.



                    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
                    pageRef.setRedirect(true);
                    pageRef.getParameters().put('var1', ApexPages.currentPage().getParameters().get('var1'));
                    pageRef.getParameters().put('var2', ApexPages.currentPage().getParameters().get('var2'));
                    return pageRef;


                    Src: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_navigation_methods.htm






                    share|improve this answer
















                    • 1




                      The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                      – sfdcfox
                      Dec 19 '18 at 11:35










                    • But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                      – Pranay Jaiswal
                      Dec 19 '18 at 11:38






                    • 2




                      Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                      – sfdcfox
                      Dec 19 '18 at 11:43















                    0














                    From Salesforce Docs:




                    When a redirect occurs the controller clears the context state.
                    Consequently we need to reset the query string parameter in the
                    PageReference's parameter map.




                    Thus your code will be.



                    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
                    pageRef.setRedirect(true);
                    pageRef.getParameters().put('var1', ApexPages.currentPage().getParameters().get('var1'));
                    pageRef.getParameters().put('var2', ApexPages.currentPage().getParameters().get('var2'));
                    return pageRef;


                    Src: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_navigation_methods.htm






                    share|improve this answer
















                    • 1




                      The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                      – sfdcfox
                      Dec 19 '18 at 11:35










                    • But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                      – Pranay Jaiswal
                      Dec 19 '18 at 11:38






                    • 2




                      Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                      – sfdcfox
                      Dec 19 '18 at 11:43













                    0












                    0








                    0






                    From Salesforce Docs:




                    When a redirect occurs the controller clears the context state.
                    Consequently we need to reset the query string parameter in the
                    PageReference's parameter map.




                    Thus your code will be.



                    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
                    pageRef.setRedirect(true);
                    pageRef.getParameters().put('var1', ApexPages.currentPage().getParameters().get('var1'));
                    pageRef.getParameters().put('var2', ApexPages.currentPage().getParameters().get('var2'));
                    return pageRef;


                    Src: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_navigation_methods.htm






                    share|improve this answer












                    From Salesforce Docs:




                    When a redirect occurs the controller clears the context state.
                    Consequently we need to reset the query string parameter in the
                    PageReference's parameter map.




                    Thus your code will be.



                    PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
                    pageRef.setRedirect(true);
                    pageRef.getParameters().put('var1', ApexPages.currentPage().getParameters().get('var1'));
                    pageRef.getParameters().put('var2', ApexPages.currentPage().getParameters().get('var2'));
                    return pageRef;


                    Src: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_navigation_methods.htm







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 19 '18 at 11:18









                    Pranay Jaiswal

                    13.4k32351




                    13.4k32351







                    • 1




                      The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                      – sfdcfox
                      Dec 19 '18 at 11:35










                    • But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                      – Pranay Jaiswal
                      Dec 19 '18 at 11:38






                    • 2




                      Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                      – sfdcfox
                      Dec 19 '18 at 11:43












                    • 1




                      The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                      – sfdcfox
                      Dec 19 '18 at 11:35










                    • But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                      – Pranay Jaiswal
                      Dec 19 '18 at 11:38






                    • 2




                      Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                      – sfdcfox
                      Dec 19 '18 at 11:43







                    1




                    1




                    The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                    – sfdcfox
                    Dec 19 '18 at 11:35




                    The parameters are still there, just hidden in a form post. They're not actually redirecting anywhere, that's just how VF works.
                    – sfdcfox
                    Dec 19 '18 at 11:35












                    But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                    – Pranay Jaiswal
                    Dec 19 '18 at 11:38




                    But when the user refreshes by clicking browser button, they would be lost unless theya re in URL params?
                    – Pranay Jaiswal
                    Dec 19 '18 at 11:38




                    2




                    2




                    Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                    – sfdcfox
                    Dec 19 '18 at 11:43




                    Maybe, it depends on how the user refreshes, honestly. Either way, it isn't as simple as writing Apex code to fix in this case.
                    – sfdcfox
                    Dec 19 '18 at 11:43

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Salesforce Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244155%2favoid-changing-visualforce-page-url%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?