I was just about to write some custom code in order to re-create parts of a SFDC page layout in JavaScript. Getting through the sections and fields of the page layout seems to be pretty manageable, but then I got to the related lists. Just reading through the Metadata API Developer Guide it states:


  • fields | string[] | A list of fields displayed in the related list. Retrieval of standard fields on related lists uses aliases instead of field or API names. For example, the Fax, Mobile, and Home Phone fields are retrieved as Phone2, Phone3, and Phone4, respectively.

I mean, who needs aliases for the fields? How does one get the API name of a field so that later can retrieve the actual data in order to populate that related list? I could not work out a way to find any relationship between a field's API name and it's alias. I even checked the DescribeFieldResult class, and could not find any references to a field's alias (thought I could map it somehow). Has anyone got a solution for this?


1 Answer 1


Don't use the metadata API for this purpose. It's not meant to be used this way, and will only frustrate you. Instead, use the Describe Layout REST API call, which looks like this:


(Record Type ID is optional if no record types are defined).

This will return a JSON object that describes the logged-in user's layout for the specified record type. The best part is, you'll get all of the configured related lists with their API names; you can directly build queries for the related data without having to resolve aliases.

I suspect that this will also help you in your endeavors generally, because you'll be able to layout the object meaningfully. The reason why the metadata API doesn't use API names is simply because its primary focus was for migrating configuration across orgs, and the team that built the feature found it convenient.

The REST API, on the other hand, is meant to be actionable especially for mobile devices, etc. I've used this interface in the past in a Visualforce page to completely render a layout with minimal fuss.

  • Is there any way to retrieve a page layout by name? In my case there might be multiple layouts available for a particular record type and using this method does not seem to allow to retrieve metadata for a specific one. I know only one can be assigned per profile per record type, but outside Salesforce we want to use a stripped down version of it, therefore I'd like to retrieve it's metadata by name or even Id. Commented Sep 4, 2017 at 7:18
  • Funny how you can do that with the Tooling API, but again, it returns the Aliases instead of the API Names... Grr Commented Sep 4, 2017 at 7:24
  • 1
    @BorisBachovski The REST API is more focused on giving you the data as a client would need it, so it doesn't have a "get layout by name or id" option. Realistically, you'd want to align the record type to the page layout, and use the record type name, at least for whatever profile you're rendering this for. I don't think you can currently get a better answer than this.
    – sfdcfox
    Commented Sep 4, 2017 at 14:26
  • Thanks @sfdcfox. I guess I have to create a global map of Alias => API Name in my scenario. Commented Sep 5, 2017 at 0:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .