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
ForceDev54ForceDev54 

Get all the fields from the page layout

Hi,

 

I have an interesting scenario. 

 

I have a page layout and consider i have 3 fields in the layout.

 

How do i get all the field api names that are available in a page layout for a custom object in apex?

 

Thanks in advance

 

 

digamber.prasaddigamber.prasad

Hi,

 

DescribeLayout() is a Soap API call, there is a Java example here,
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describelayout.htm

Mike KauravMike Kaurav

Hello ForceDev54

 

I give you a sample code where you can find how can i get all field of any object dynamically.

I think this is best answer for you. if you find this is good one for you then give me feedback.

 

 

public map<string, schema.sObjectType> so = schema.getGlobalDescribe();

 

 

schema.sObjectType allSelectedObject = so.get(val);
        // Fetching Field Result
        schema.DescribesObjectResult result = allSelectedObject.getdescribe();
        map<string, schema.sObjectField> f= result.fields.getMap();  
        for(schema.sObjectField SFields: f.values()){
            AllFields.add(new selectoption(SFields.getDescribe().getName(), SFields.getDescribe().getLabel()));
            
            system.debug('----------SFields.getDescribe().getLabel()----------'+SFields.getDescribe().getLabel());
        }

 

if you find any dificulty with this you  can contact me again.

 

Thanks.