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
NongNong 

How to set VF page override Account detail page for specific record type?

Dear All,

 

I have 2 record types of Account object  Record Type A and B.

 

I just create one visualforce page and would like to override it for Account detail page for record type 'A'.

 

I found  if we change setting by follow the steps below.

This setting is to override on every record types.

 

Setup>Customize>Accounts>Button and Links> Select  'View' > Select my VF page.

 

 

Could you please advise how we can we set to override only Account record type 'A'

 

 

Thank you very much in advance for your advise.

 

Regards

Anong

Ritesh AswaneyRitesh Aswaney

Dont think you can do this via config. You will have to have a redirect (return relevant PageReference) based on the record type using apex code in your controller.

Damien_Damien_

What you want to do, is create that custom Visualforce page but use the <apex:details> in order to conserve the one you do not wish to override.

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

<apex:page standardController="account" extensions="YourExtensionHere">

  <apex:form rendered="{!NOT(recordTypeA)}">

    <apex:detail /> <!-- This will render your default setup for any record type not A -->

  </apex:form>

  <apex:form rendered="{!recordTypeA}">

    <!-- Your custom visualforce form goes in here for record type A -->

  </apex:form>

</apex:page>

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

You MUST use an extension.  Your extension at a minimum must determine what a record type is and set the public boolean recordTypeA in the constructor.

Kent ManningKent Manning

Hi Nong,

 

At first glance this looks easy.  In reality it is much harder to do than it appears.  I have been trying to do this with the Contact page and here are some of the ways I approached the problem.  What I did was create a page layout for record type A.  I placed a blank section on the page and then embedded my visualforce into that section.  This worked great for viewing data.  The problem came when trying to edit this data.  What happens is that when the user press the edit or new buttons, they are taken to the standard edit page and your visualforce page is no longer viewable.  Therefore, I thought let's override the new button, use some apex code to redirect the user based on record type.  I found a good article on the community discussion board and modeled my code after this article:

http://boards.developerforce.com/t5/Visualforce-Development/Record-Type-Selection-Page-Over-riding/m-p/193387.

 

I ran into some problems with record type redirecting.  On major issue - if you have more than one record type and the user profiles are defaulted to one particular type then the page redirect code will not work properly.  The reason is that when you try to retrieve the record type from the page,  the record type comes back as null.  Therefore, the redirect code doesn't know where to send the user and it just defaults to the standard edit page.  As long as you have the user select the record type to use each time, then the page redirect works great.  So just be aware of that limitation.  Salesforce support recommended that I base my page redirect on the profile rather than the record type so that this problem can be avoided.  There is an example of this in the Force.com Cookbook on page 55. I have modified my code to work off of the profile rather then the record type.

 

Hope this helps - at least lets you avoid some of the pitfalls I've found.

Damien_Damien_

He's right, you should use the code I gave you but use the profile to lookup what PageLayout you should be using.  You would then replace my recordType logic on the top part with the PageLayout based off profile logic.  Unless of course every user uses the same Page Layout for a given record type.  If this is the case then my earlier way would work fine, but it could give you trouble in the future if you wish to change it up.

NongNong

Dear All,

 

Thank you very much everybody for all the advises, at the beginning i tested on Damien 's solution and i found it was ok but i did test it well as Bioscience found some problems before.

 

I am going to try follow Bioscience suggestion and will come back to update you all again.

 

Best Regards

Anong