I have a requirement where we have to retrieve all the fields under an Object say Standard or Custom. I am using FinancialForce Metadata service class. I can Retrieve all the Custom objects and all the Custom fields independently but my requirement is to retrieve only the custom fields only under a certain object. Below code logic is used to retrieve custom objects and fields.
MetadataService.MetadataPort service = createService();
List < MetadataService.ListMetadataQuery > queries = new List < MetadataService.ListMetadataQuery > ();
MetadataService.ListMetadataQuery queryLayout = new MetadataService.ListMetadataQuery();
MetadataService.FileProperties[] fileProperties;
queryLayout.type_x = 'CustomObject'; // 'CustomField'
queries.add(queryLayout);
fileProperties = service.listMetadata(queries, '36.0');
List < String > fullNames = new List < String > ();
if (fileProperties != null) {
for (MetadataService.FileProperties fileProperty: fileProperties) {
fullNames.add(fileProperty.fullName);
}
}
fullNames.sort(); // List of Custom objects/fields
private static MetadataService.MetadataPort createService() {
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.endpoint_x = //'Org End point';
service.timeout_x = 120000; //Setting the time out
service.SessionHeader.sessionId = // AOauth Access Token
return service;
}
Please help. Thanks.