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
Anuj.ShuklaAnuj.Shukla 

help required in redirecting to a new page

Hi,

 

We have built a new tab as "partner" which is very similar to standard tab Account.

 

What we need to do:

In Account tab, when new Account button is created,

  • we need to see what is role of logged in user
  • if logged in user role is Channel Sales manager, redirect to new partner page
  • if logged in user role is NOT Channel Sales manager, continue as expected and show create new account page.

I have overridden new Account button and am calling an apex page on it. On the extension of this apex page, I have written out the logic to get the logged in user role. I am able to get the role of logged in user.

 

This is well printed on Systems debug.

 

But, I do not know how to redirect to partner apex page (is case it is CSM) or continue to new standard Account page (in case non CSM) from an apex class.

 

Please help me on this one.

 

 

Thanks,

Anuj, the 'Newbie'

kritinkritin
PageReference pageRef = new PageReference('http://www.google.com'); or PageReference pageRef = ApexPages.currentPage(); or here you can use and read recordtype and recreate your URL for the required record type.
Anuj.ShuklaAnuj.Shukla

Hi All,

I have created this apex page 'IntermediatePage' and I have overriden NEW Account button and overriden it to below page

<!--This is IntermediatePage apex page-->
<apex:page standardController="account" extensions="overrideCon" action="{!redirect}">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is intermediate Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>


Below is my overrideCon apex class

public class overrideCon {
       String recordId;
        
    public overrideCon(ApexPages.StandardController controller) { }
     
    public PageReference redirect() {
        
        Boolean toAccountPage=true;
           
        PageReference pr;   
        if (! toAccountPage){           
            pr =  Page.RedirectedPage;           
            //pr.setRedirect(true);   
        } else {             
            pr = ApexPages.currentPage();
            pr.setRedirect(true);                                                     
        }        
        return pr;  
                  
    }
}

When I keep boolean toAccountPage to false, it very well goes to newly created apex page "RedirectedPage" and I see that page.

But when I want to keep boolean toAccountPage to true, I want to see standard create Account page which is not happening here.

Can anyone please help me in achieving this ?


Thanks,
Anuj

Anuj.ShuklaAnuj.Shukla

Hi,

 

I have changed overrideCon as below

 

public class overrideCon {
    String recordId;
        
    public overrideCon(ApexPages.StandardController controller) { }
     
    public PageReference redirect() {
        Boolean toAccountPage=true;           
        PageReference pr;   
        
        if (! toAccountPage){           
            pr =  Page.RedirectedPage;
            pr.setRedirect(true);
             
        } else {
              //pr =  Page.RedirectedPage;   
              pr =  new ApexPages.StandardController(new Account()).view();                                                                   
              pr.setRedirect(true);                                                                   
        }
                
        return pr;   
                      
    }
    
}

 

Still it is not taking me to create new account page.

This time, it just stops at the intermediate page and I see the message n screen, This is intermediate Page

 

 

Thanks,

Anuj

NaishadhNaishadh

Here  ApexPages.currentPage(); refer to your current VF page and not the standard page. To redirect to the default account create page use

pr = new Pagereference('/001/e?retURL=/001/o');