Avoid changing Visualforce page URL
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
add a comment |
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
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
visualforce
asked Dec 19 '18 at 10:34
Ganesh Bhosle
1,3041935
1,3041935
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 19 '18 at 10:58
Tushar Sharma
24.7k52148
24.7k52148
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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