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
paddupaddu 

Urgent: PageReference is not working

Hi All,

I have a custom button on VF page (say open), when clicking on the button the page should open in a new window; it is working when Development mode is on (checked) , when switched off the development mode the page is opening inline on VF page only. Any help is highly appreiciated.


<apex:pageblockButtons location="top">
            
    <apex:commandButton action="{!tOpen}" value="Open"/>
            
</apex:pageblockButtons>



 public PageReference tOpen(){  

        PageReference pref= new PageReference('/'+ tid +'?retURL=%2F'+cid);
        pref.setRedirect(true);
        return pref;
 
    }



Thanks a ton inadvance!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I wouldn't expect this to open in a new window regardless of developer mode - you have just coded a button to submit the form and the action method returns a client side redirect. There's nothing in there to open a new window.

 

You can't mark the page reference to open a new window, as that isn't part of the HTTP protocol.  If you just want to open a new window to another URL, you'd do better to have an apex:commandlink, which allows you to specify a target, or an onclick handler to open the window via javascript.

 

 

 

All Answers

bob_buzzardbob_buzzard

I wouldn't expect this to open in a new window regardless of developer mode - you have just coded a button to submit the form and the action method returns a client side redirect. There's nothing in there to open a new window.

 

You can't mark the page reference to open a new window, as that isn't part of the HTTP protocol.  If you just want to open a new window to another URL, you'd do better to have an apex:commandlink, which allows you to specify a target, or an onclick handler to open the window via javascript.

 

 

 

This was selected as the best answer
paddupaddu

Thanks for th reply bob_buzzard.

 

Can you please give sample code for onclick hanlder to open the window.

 

Thanks a ton in advance.

bob_buzzardbob_buzzard

Do you need to hit the action method first, or is it just to open a URL from one of the controller properties?

paddupaddu

I want to open a URL when clicked on Command button.

 

 

Thanks

bob_buzzardbob_buzzard

That doesn't help I'm afraid.  Do you need to hit the action method first, or does the page know enough to create the URL.

paddupaddu

when clicked on the button, the page should redirect to the url specified in the action method.

Actually I am overriding Activity History section here , when cliked on open, repective Activity History should open in a new page.

 

 

Thank you.

bob_buzzardbob_buzzard

You can open a URL from a command link as follows:

 

<apex:commandButton value="Submit" onclick="window.open('http://www.google.com', 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); return false;"/> 

 Note the "return false" at the end of the onclick handler - this stops the page being submitted back as well as the popup window being opened.

 

 

paddupaddu

Thanks for the reply bob, how to use query paramters in the URL, say ('/'+ tid +'?retURL=%2F'+cid) instead of 'google.co.in'  in the give sample code.

 

 

Thank you.

bob_buzzardbob_buzzard

Assuming you have controller properties for tid and cid, you should be able to drop them into the URL:

 

<apex:commandButton value="Submit" onclick="window.open('/{!tid}?retURL=%2F{!cid}', 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); return false;"/>

 

another way to do this is to have a getter in your controller that builds the URL and allows the page to use that directly.

Eva DeLoriolEva DeLoriol
I had the same issue where the command button loaded the VF page inline.  I was able to solve the issue with the onclick event; 

<apex:commandButton onClick="parent.location.assign('/apex/VFPage')" value="Submit"/>

The parent location is essentially replaced with the new location, keeping the previous page in history so that the user can still access the previous page using the back button.