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
MJRDeveloperMJRDeveloper 

Overriding edit with a visualforce page for one record type

I know I have seen a solution using java, but I want to avoid that if possible. I created a visualforce page that uses the standard controller for the account object. It uses action to call the mypage function, which returns a pagereference.

 

<apex:page standardcontroller="account" extensions="recordtypeforwarderextension" action="{!mypage}"/>
 
 

 

public with sharing class recordtypeforwarderextension {    
public recordtypeforwarderextension(ApexPages.StandardController controller) {}        

public pagereference mypage(){return page.RT2;}    
}

 

Right now, the controller is not checking for record type. I just want to get the forwarder to forward properly. The issue that I have is that the forwarder page and RT2 both use the standard controller for the account object. When  I change RT2 to use a standard controller for any other object,, like Contact, the forwarder works. When both use the standard controller for Account, it doesn't. Any ideas? RT2 is just a dummy page. The code I am using is below. If I can get this to work, I can have the mypage function look at the Record Type and if it is the right one, it will go to the visualforce edit page. If it is any other record type, it will forward to the standard salesforce editor. Thanks!

 

<apex:page standardController="account">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page: rt2
  <!-- End Default Content REMOVE THIS -->
</apex:page>
		

 

bob_buzzardbob_buzzard

When you say it doesn't work when you use the account controller, does that mean that you get an error, blank page, something else?

MJRDeveloperMJRDeveloper

I mean that it doesn't forward. It stays on the original visualforce page.

bob_buzzardbob_buzzard

Try setting the redirect property on the returned reference to RT2 to true.   E.g.

 

PageReference pr=Page.RT2;

pr.setRedirect(true);

 

return pr;

 

I seem to recall reading that you need to do this if you are redirecting to a page with the same controller as the current page.