/**
@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
Could you please let us know where this would be useful?
In many scenarios, we actually use this. For example, If you want to find unused fields, you can find them with the help of the above.