How open in new Tab for PageReference?

To open the URL in new Tab for PageReference, kindly use <apex:commandLink/>.

Sample Code:

Visualforce page:

<apex:page controller="Sample">
<apex:form >
    <apex:pageblock >
        <apex:commandlink action="{!switch}" target="_blank">
            <apex:commandButton value="Switch"/>
        </apex:commandLink>
    </apex:pageblock>
</apex:form>
</apex:page>


Apex Controller:

public class Sample {  
   
    public Sample() {
    }
   
    public pageReference switch() {
        PageReference pageRef = new PageReference('http://www.google.com');
        pageRef.setRedirect(true);
        return pageRef;
    }           
}

8 comments:

  1. Can anyone explain the code for accessing object from the controller method?

    ReplyDelete
    Replies
    1. Check this links for more info

      http://www.infallibletechie.com/2013/02/how-to-fetch-data-from-controller-and.html

      http://www.infallibletechie.com/2013/02/how-to-fetch-data-from-controller-and_6.html

      Cheers!!!

      Delete
  2. Can you explain how to navigate to a new page like this in service cloud console? I have an apex class that contains the code below. I need to modify it because it does not work in service cloud.

    return new PageReference('/apex/CustomVisualForcePage?id=' + objectId);

    ReplyDelete
  3. if you pass querystring paramter isdtp=vw, and set in visualforce page attributes showHeader={!IF($currentPage.parameters.isdtp==null,'true','false') same applies for sidebar. if you dont set these you will get page error visualforce page can't be displayed with in iframe security issue in service console.

    - Pawan

    ReplyDelete
  4. Worked perfectly... Thanks

    ReplyDelete
  5. Just what I was looking for. Works a treat. Thank you.

    ReplyDelete
  6. All of the post are simple and very useful.Thank you.

    ReplyDelete