+ Start a Discussion

describeLayout() or Metadata API

How i can get the layouts metadata from the apex controller ?

The metadata API has a method describeLayout() or getDescribeLayout() but i cannot make it works at the controller.

If that is not possible , how i can connect to the metadata api from the apex controller?

Currently metadata api calls are not available in Apex.
And Apex Describe only gets RecordType, and Field info.

And the describeLayout() method is in the Web Services API not the Metadata API.

What are you trying to solve, because using VisualForce you have access to some Layout information.
Thanks for the reply and the aclaration about the apis , what i am trying to do is to build a standard object detail at a visualforce page build by me, and if i want to preserve layout settings made by the administrator for the current user profile, i need to know what fields show or hide.

I was searching for a way to do that, and the one that seems better to me is with the getDescribeLayout method, but if you have a suggestion i will appreciate :).

A lot of thanks again for the reply.
Sorry about my english i'm not  a native english speaker.


can't you just use the apex:detail element ?
Mmh, i dont know if i can use that, wher i can found information about ?

i can personalize the look of the fields ?

Message Edited by Br1 on 10-15-2008 10:43 PM
check the VF docs, and/or the component reference.

mikef wrote:
Currently metadata api calls are not available in Apex.
And Apex Describe only gets RecordType, and Field info.

And the describeLayout() method is in the Web Services API not the Metadata API.

What are you trying to solve, because using VisualForce you have access to some Layout information.


Can you cofirm please, if describeLayout() functions are available in Spring 09 release or not. I'm trying to read layout information saved for an Object and display ALL fields and Sections in the layout descriptions in custom VF page, and no I cannot use <apex:detail /> tag as I want to search and replace some fields  in the display of the record :(






No one has to confirm anything, just look in the Apex docs.

There is no support for describeLayout() .


So there is a work around that is kludgy but might get what you want.

You would have to create a new page layout with all the fields and sections you want to display.

Add a record type to the object and assign every profile the page layout for this new record type.

Your visualforce page, when called will first save the record with the new record type then show the visualforce page.

When your users are done with the page it has to resave the record in the old, or master record type.


This is a lot of work to do what you want.

And I am finding it hard to figure out what your use case is.

Why would you ever want to show a user the details of a record, but replace some fields?

What is your use case?


Also you might want to try and use JavaScript to navigate the DOM tree after the page is rendered and replace your fields that way.


The use case, or problem is this....


We have an object and a page layout. We want to do some specific things on the page layout, such as custom Account/Contact dependent drop down <SELECT> boxes and possibly other things. We do not want to take the customization of the page layout away from the user, if they decide they want to customize it themselves.


So, first though would be to put these 2 field in a visual force page and drop that on the page... BUT we run into a situation where on EDIT of the page layout, these fields will not display, only on Detail view does the Visual Force page, added to the page layout appear.


What we thought is, if possible, grab the page layout and all its components, regenerate it on the fly in a visual force page, and just replace the "special" fields that we deem need to be presented a different way, with our custom layout for those fields.


Any advice appreciated... Thanks


and the out of the box dependent picklist fields won't work because they are only dependent on the current record's data?

do you want to select a contact and other fields on the account become filtered because of the type of contact?


Can you list the steps the user would take if you could do anything you wanted?


for a very simple e.g. what if I want to change the Account / contact popup fields with select options (dropdowns), and also want to preserve Standard Customizations available to users in page layout.


I thought those API calls would have helped me a lot in this concept.


So this is a feature that people have asked for, it's called filtered lookups.

I am not sure when this is coming out, or if ever.


In the mean time you can provide a custom lookup Visualforce page and call this page on the detail account view, with a button.

This is not ideal but is a work around.


That will not work as VF page will not show up on EDIT screen of the default layout, it is ONLY displaye don detail layout.


If we can display the VF page in Edit screen also, that would be so great if you could guide me on how to do so :).


Not in the edit page but the details page.

Bottom line there is no way to do what you want, you need to look for a work around.

I'm looking for that workaround Unless that workaround is a compromise for default standard layout popup fields for contact/account :(

I am searching for a solution for my problem and found this thread. I want to create a PDF  that will show some or all sections with some/all fields with completely custom layout. So, is there a way to somehow in apex retrieve information about loyout of specific object and record type? That way I will not need to change the code every time when client add new field to a section. I would expect that there should be a way to do following:


String markup = '<table>';

PageLayout pl = PageLayouts.get(objectName, recordTypeId);

foreach(Section s in pl.sections){

     markup += '<tr><td colspan=2>' + s.Name + ''</td></tr>';

           foreach(Field f in s.fields){

                   markup += '<tr><td>' + f.Name+ '</td><td>' + f.Value+ '</td></tr>';



markup += '</table';