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
UU 

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.
https://developer.salesforce.com/forums/?id=906F0000000AG13IAG

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. 

Thanks
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
1) http://amitsalesforce.blogspot.in/2015/11/apex-describe-dynamic-retrieval-of.html
 
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());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }

    
    // Find the fields for the selected object
    public void showFields() 
    {
        listField.clear();
        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();
            listField.add(wObj);
        }
    }

    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:pageblockbuttons>
            
            <apex:pageblocksection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Object Name</apex:outputLabel>
                    <apex:selectList value="{!selectedObject}" size="1">
                        <apex:selectOptions value="{!ListObejectName}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageblocksection>
        </apex:pageBlock>
        
        <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"/>
            </apex:pageblockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

Let us know if this will help you

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

Thx
UU
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.

Thanks,
U
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 http://salesforcecodex.com/2020/05/find-list-of-all-fields-on-page-layout/ for this. You will be able to get page layout fields information.