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
Suman KunduSuman Kundu 

How to add a key value pair to url from Apex

I am working on a visualforce page where there is a extension controller. Now in this controller, I am overriding the save method which returns PageReference. Here when I am returning Page.AccountTabbed, it makes the url as follows:

https://c.cs3.visual.force.com/apex/AccountTabbed?id=001Q000000Q2rMJ&sfdc.override=1

 

But I need the url like:

https://c.cs3.visual.force.com/apex/AccountTabbed?id=001Q000000Q2rMJ&sfdc.override=1&openTab=NewSubscription

[Need to add 'openTab=NewSubscription' at the end]

 

I have tried it like

                PageReference pageAcc = Page.AccountTabbed;
                pageAcc.getParameters().put('openTab', 'NewSubscription');
                return pageAcc;

But it doesn't change the url.

 

Can anybody help me out...

bob_buzzardbob_buzzard

The URL only changes when the browser is redirected to the new page.  If you are already on this page (or a page with the same controller) the browser remains where it is.  

 

Where are you performing the redirect from?  Is it a page action attribute method?

Suman KunduSuman Kundu

I am using AccountTabbed visualforce page. When the Save button in it is being clicked, its controller's save method is called. From which I am calling the accountTabbed page again adding a new parameter(key-value pair).

bob_buzzardbob_buzzard

You'd need to set the redirect attribute on the returned pageference to true to achieve this, i.e.

 

pageAcc.setRedirect(true);

This will, however, result in a full browser redirect, which will cause a new instance of the controller to be created and the previous instance to be discarded.

Suman KunduSuman Kundu

But I have to keep that instance alive. Is there no other option?

bob_buzzardbob_buzzard

If you are going back to the same page with the same controller instance, why do you need to put the information on the URL - can you not use a controller property?