4

I'm trying to do some field level data analysis and it would be helpful to be able to pull out the CreatedDate and CreatedBy (Name) for each Custom Field (not individual records) on both Standard and Custom Objects.

I've experimented a bit with the Tooling API to retrieve this but wondering if there's an easier way.

1
  • It seems to be available in the Metadata api as part of the FileProperties type but not sure how I'd retrieve that from Apex for a CustomField link
    – Jamie G
    Jun 2, 2015 at 23:16

1 Answer 1

2

I figured it out by using the listMetadata method of the Metadata-API Apex wrapper provided by Financeforce.

https://github.com/financialforcedev/apex-mdapi

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();    
MetadataService.ListMetadataQuery queryCustomField = new MetadataService.ListMetadataQuery();
queryCustomField.type_x = 'CustomField';
queries.add(queryCustomField);    
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);

// Debug results
for(MetadataService.FileProperties fileProperty : fileProperties) {
  System.debug(fileProperty.fullName + ': createdby=' + fileProperty.createdByName + ', createddate=' + fileProperty.createdDate + ', manageableState=' + fileProperty.manageableState);
}

You must log in to answer this question.

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