How to find the fields that are part of the Page Layout in Salesforce?

How to find the fields that are part of the Page Layout in Salesforce?

Sample Code:
 
List < Metadata.Metadata > layouts = Metadata.Operations.retrieve(
Metadata.MetadataType.Layout, new List < String > { ‘Account-Account Layout’ }
);
Metadata.Layout layout = ( Metadata.Layout )layouts.get( 0 );
for ( Metadata.LayoutSection layoutSection : layout.layoutSections ) {

for ( Metadata.LayoutColumn layoutColumn : layoutSection.layoutColumns ) {

if ( layoutColumn.layoutItems != null ) {

for ( Metadata.LayoutItem layoutItem : layoutColumn.layoutItems ) {

if ( layoutItem.field != null ) {

System.debug( ‘Field is ‘ + layoutItem.field );

}

}

}

}

}

 
In the above code, Account-Account Layout is Object Name hyphen Page Layout Name.
 
Output:
 

 

Leave a Reply