/**
@createdBy : ways2salesforce
**/
public class FieldAuditController{
 public static void usedField(String objName,List<String> listOfLayout){
    List<Metadata.Metadata> layouts = 
        Metadata.Operations.retrieve(Metadata.MetadataType.Layout,  listOfLayout);
    Metadata.Layout layoutMd = (Metadata.Layout) layouts.get(0);
    
    for (Metadata.LayoutSection section : layoutMd.layoutSections) {
        for (Metadata.LayoutColumn column : section.layoutColumns) {
            if (column.layoutItems != null) {
                for (Metadata.LayoutItem item : column.layoutItems) {
                    System.debug(item.field);
                }
            }
        }
    } 
 }
}

//Calling the method.
FieldAuditController.usedField('Account',new List<String>{'Account-Account (Sales) Layout','Account-Account Layout'});

THANKYOU | HAPPY LEARNING

2 Replies to “How to retrieve fields dynamically from page layout | How to extract field from pagelayouts.”

Leave a Reply

Your email address will not be published. Required fields are marked *