function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alfonso MoranAlfonso Moran 

Query deleted custom fields in Objects

We are having issues with some integration packages that query some of our salesforce objects and transfer the data to other platforms; however, occasionally there are fields that are deleted without our knowledge and we would like to find out before the packages run and break when a field is no longer found, so we would like to create a query to find Deleted custom fields.
We can see the CustomField object shows us new and/or changed fields but we don’t know how to query for recently deleted fields. Do you know of any soql query that will tell us that? 
Alain CabonAlain Cabon
Hello,

With "Use tooling API" checked (query editor in the developer console), you can get the fields with a name ending with "_del" but that is not sufficient because you can create active fields with a name ending with "_del".

Therefore, you need to check if these fields with a name ending with "_del" are not active in the metadata with a new request using TableEnumOrId.

Tooling queries:
select Id,DeveloperName,ManageableState,TableEnumOrId from customfield where DeveloperName like '%_del'
select id,developername from customobject where id = '<TableEnumOrId>'
Anonymous windows:
String selectedObject = '<developername>';  // Account , Test__c
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType objectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = objectSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()){  
       system.debug('field name:' +  fieldName + ' label:' + fieldMap.get(fieldName).getDescribe().getLabel());
}