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

Get Fields APIs on Page Layout

Hi experts,

I would like to get all fields API names on specific page layout and use the fields in SOQL. Then I want to display the query results on Visualforce page.

I asked Salesforce Support for help but they cannot answer this question so I searched on Discussion Forums and found some articles about DescribeLayoutResult.

I read links for references but I'm just confused and not sure what to do.

Does anyone provide me simple but complete code to display field details on Visualforce page so that I can amend it for my use.
It would be nice if you can use Lead object and Name field.

Thank you in advance.

William TranWilliam Tran
You can get it via a SOAP or web services call.  

Not sure what you are trying to do, but for now it's probably best for you to get all the fields manually then construct the SOQL.

If you need it to be dynamic, you would need to learn SOAP/web services or get a developer to help you.

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
public with sharing class DescibeDemoController 
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public List<FieldWrapper> listField{get;set;}

    public DescibeDemoController() 
        listField = new List<FieldWrapper>();

    // find all sObjects available in the organization
    public  List<SelectOption> getListObejectName() 
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;

    // Find the fields for the selected object
    public void showFields() 
        Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
        for(Schema.SObjectField sfield : fieldMap.Values())
            schema.describefieldresult dfield = sfield.getDescribe();
            FieldWrapper wObj = new FieldWrapper();
            wObj.fieldName = dfield.getLabel ();
            wObj.fieldAPIName = dfield.getname();

    public class FieldWrapper
        public String fieldName {get; set;}
        public String fieldAPIName {get; set;}

<apex:page controller="DescibeDemoController">
    <apex:form id="Describe">
        <apex:pageBlock id="block2" >
            <apex:pageblockbuttons location="top" >
                    <apex:commandButton value="Show Fields" action="{!showFields}" />
            <apex:pageblocksection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Object Name</apex:outputLabel>
                    <apex:selectList value="{!selectedObject}" size="1">
                        <apex:selectOptions value="{!ListObejectName}"/>
        <apex:pageBlock id="result" title="Field Detail for {!selectedObject}" rendered="{!if(listField.size > 0 ,true,false)}"   >
            <apex:pageBlockTable value="{!listField}" var="field" rendered="{!if(listField.size > 0 ,true,false)}"> 
                <apex:column value="{!field.fieldName }" headerValue="Name" />
                <apex:column value="{!field.fieldAPIName }"  headerValue="API Name"/>

Let us know if this will help you

Amit Chaudhary
William TranWilliam Tran
Just for clarification - getGlobalDescribe() returns fields for objects not specific page layouts.

Thanks for both of your posts.

As to getGlobalDescribe() method, I have already tried and found out this method does not do what I want.

I'm writing all fields in Apex manually now.

William TranWilliam Tran
That's what I have done in the past.  Please mark best answer to close this thread. Good luck.  Thx
Dhanik L SahniDhanik L Sahni
Please refer link for this. You will be able to get page layout fields information.