+ Start a Discussion

I want UsePolicySuccess page to be opened in the same page not in a new page(new window).



I have below method which is called from a button click in a visualforce page.


 public PageReference saveUsePolicy() {


       User usr= [SELECT Use_Policy__c from User where Id=:UserInfo.getUserId() and IsActive=true];
        usr.Use_Policy__c = true;
        update usr;
        PageReference pageRef = Page.UsePolicySuccess;
        return pageRef;      



It is updating user record upon button click. Also It is redirected to open new page(UsePolicySuccess).


I want that page to be opened in the same page not in a new page(new window).


Share your thoughts on this.


Thanks in advance..


Andy BoettcherAndy Boettcher

The native PageReference doesn't do anything to control client behavior like that, but here is an earlier discussion post on the topic - perhaps this is what you're looking for?






how can achieve that page can be executed in the same page not in another page..

Andy BoettcherAndy Boettcher

try setRedirect(true)




I tried that too..

It is calling another page but that page is opened in a new window.


I don't want new window to be opened for this.



Abhinav GuptaAbhinav Gupta

Can you please share the page code snippet too ?


please find the code below:


First Visualforce page:

<apex:page controller="UsePolicyPage" sidebar="false" showHeader="false" tabStyle="account" >
<apex:form >
<apex:outputPanel styleClass="custPopup" layout="block">
<apex:pageBlock >

<apex:pageBlockSection title="PURPOSE">
<p>The wide array of resources, communication, and content sharing available through Chatter all introduce new, and streamline current, business opportunities, and will introduce new security and privacy risks. In response to the risks, this policy describes the JDA Software official policy regarding Salesforce Chatter and Chatter Free.</p>

<apex:pageBlockSection title="SCOPE AND APPLICABILITY">
<p>This policy applies to all workers, employees, contractors, consultants, and temporaries, who use Chatter with JDA Software.  The policy applies to all those who use the Chatter and represent themselves as being connected in some way with JDA Software. All of these Chatter users are expected to be familiar with and fully comply with this policy. Questions about the policy should be directed to the reader’s departmental Information Security coordinator or the corporate Information Security manager. Violations of this policy can lead to revocation of system privileges or additional disciplinary action up to and including termination.</p>

<apex:pageBlockSection title="REQUIRED APPROVAL ">
<p>Required Approval - JDA Software users must not access Chatter without a proper understanding of the associated personal and business risks.  In order to receive Chatter access privileges, all users must complete the JDA Software associated training posted here: Salesforce Chatter training (Insert link), Chatter Free training (Insert link).</p>

<apex:pageBlockSection title="INFORMATION INTEGRITY">
<p>Chatter Content - All information posted to Chatter, including posts and file attachments is considered confidential property of JDA Software. The content is monitored, archived, is discoverable, and subject for review. Content can be deleted by JDA Software at any time if deemed out of compliance with this “Salesforce Chatter Acceptable Use Policy For Users”.</p>
<p>All information posted to Chatter, including posts and file attachments must be relevant business related content. The use of Chatter for personal use is prohibited.</p>
<p>Groups –Chatter users must refrain from creating groups unless they have been appointed from the respective Line of Business to be a “Group Owner”. The “Group Owner” will create, delete, and assign a group manager if applicable to manage membership of all Salesforce Chatter groups they are responsible for. The Group Owner will all provide oversight of all aspects of each group they are responsible for. </p>
<apex:actionStatus id="submit">
    <apex:facet name="stop">
        <apex:commandButton value="I Agree" action="{!saveUsePolicy}" status="submit"/>
 <style type="text/css">
            border-width: 2px;
            border-style: solid;
            z-index: 9999;
            left: 50%;
            position: absolute;
            /* These are the 3 css properties you will need to change so the popup
            displays in the center of the screen. First set the width. Then set
            margin-left to negative half of what the width is. You can add
            the height property for a fixed size pop up if you want.*/
            width: 900px;
            margin-left: -450px;
            opacity: 0.70;
            filter: alpha(opacity = 70);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;



Controller code:


public with sharing class UsePolicyPage {

    public PageReference saveUsePolicy() {
        Datetime myDateTime = datetime.now();
        User usr= [SELECT Use_Policy__c,Use_Policy_Date__c from User where Id=:UserInfo.getUserId() and IsActive=true];
        usr.Use_Policy__c = true;
        usr.Use_Policy_Date__c= myDateTime;
        update usr;
        PageReference pageRef = Page.UsePolicySuccess;
        return pageRef;



Second Visualforce page:

<apex:page title="Use Policy Setup" sidebar="false" showHeader="false">
   Your User Acceptance Policy Saved on {!$User.Use_Policy_Date__c}
   <p>User Name: {!$User.Username}</p>