0

I want to extract metadata of custom fields such as label, api name, data type along with the createddate,createdby values of the fields for all objects of my project into an excel sheet. Also if the custom field is of picklist or formula type I want to get the associated picklist values and the formula. Is there any entity which can be queried to get these details.

I tried using FieldDefinition object but i am only able to get the label, apiname and data type of fields.

SELECT Label, DataType, QualifiedApiName FROM FieldDefinition where EntityDefinition.developername = 'Account' 

I came across CustomField object which seems to give the createdate and createdby values but for some reason i am unable to locate this object in devconsole resources to see what more details i can get from this entity. Is there a way to apply filter to this entity and extract the remaining information and may be merge the two excels (one from fieldDefinition object and other from CustomField) if needed. Otherwise, what would be the best approach to fulfil my requirement.

3
  • There are free tools that can inspect metadata and create CSVs/Excels -- consider those rather than doing something bespoke
    – cropredy
    Commented Oct 3 at 15:33
  • @cropredy could you please suggest some free tools that can help.
    – starhunter
    Commented Oct 3 at 16:41
  • just do a Google search on "export salesforce metadata to excel"; one item that came up is packmagix.com but there are many such tools so read what people have to say about them
    – cropredy
    Commented Oct 4 at 1:25

1 Answer 1

0

There are different Schema classes in Salesforce to help with this. You can use DescribeSObjectResult link class to get metadata related to an Object. In a similar way you can use DescribeFieldResult link to get metadata related to the field.

You can get DescribeSObjectResult class for an object and then iterate over it to get different fields metadata.

SObjectType sObjectType = Account.sObjectType;  // Replace with the specific object you're working with
Map<String, Schema.SObjectField> fieldsMap = sObjectType.getDescribe().fields.getMap();

for (String fieldName : fieldsMap.keySet()) {
    Schema.SObjectField field = fieldsMap.get(fieldName);
    Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
    
    // Get the field API name and label
    String apiName = fieldDescribe.getName();
    String label = fieldDescribe.getLabel();
    
    // Output or process as needed
    System.debug('Field API Name: ' + apiName + ', Label: ' + label);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .