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

Replacing Page Layouts with VF Pages

I have seen examples of embedding VF pages in Page Layouts but I have not seen examples of REPLACING Page Layouts with VF pages.

We have a Custom object that has a dozen Record Types that are displayed via a half dozen different page layouts. The users would like to add some additional fields to the layouts that would require creating a VF page to implement. Is it possible to do this?

Can I replace my Page Layouts with VF pages that fulfill the same function but display the custom data users need/want?
I could be wrong here but I do not think VF respects Page Layout or Record Types in that the fields are all available to use in a VF page but you cannot specify what Page Layout or Record Type is used without doing some significant controller work.

However, we wanted to create some VF components and access them in standard page layouts so I create the components and then added them to the relevant Page Layouts so that when the page layout is accessed through record types the VF components would display.

The components in question were simple Text as fields but you should be able to create anything VF wise as a component in a page layout, fields, sections, related lists, details etc.

Message Edited by MATTYBME on 01-07-2009 03:31 PM
The answer is yes, but with some caveats.

You can override the view, edit, new, etc. pages for your custom object.  Let's say in this case we're talking about overriding the edit page.

If you create a page that uses the standard controller for that custom object (you can use apex extensions for any custom logic you need), you can use it to override the Edit action of the object.  Thus any time someone wants to edit a record of that object, they'll be taken to your page instead of the normal edit page.

However as far as page layouts go, you'll have a little less luck.  The only component right now that respects page layouts is the apex: detail component, and it's a display component, rather than an edit component.  It will respect your page layout based on record type as well.  However if you need to add or subtract anything to the detail portion, you will have to construct the detail portion yourself using apex: pageBlock and outputField components.  Similarly if you want the edit version of this, you need to construct that using pageBlock and inputField components.

Based on the recordTypeId of the object you can do conditional redirecting or conditional rendering so that the right page or portion of the page shows up for the right recordType, but you'll have to do the work there to recreate your page layouts.
I am in the same boat here we have tons of page layout and would like the ability to just override just the address part of the all the layouts to do some validation prior to save.  The ability to do client side validation using standard the page layout would be soooo nice. 
I was hoping there was a way to get a <apex:detail mode="edit"> and just use javascript to add events after load.
The only other option I can think of is to get the metadata of the layout (like what the API describeLayout provides) and role you own render.    I dont know how long it would take to render the page but its possible.  Also, Not sure how easy it would be to binding the data back so that may be a bit tricky too.
Has anyone out there done this?
Here are some ideas that tie in closely with this use case:

I've also included dependent pick lists as for this to work I'm guessing VF would need to support Record Types and page layouts.