You need to sign in to do that
Don't have an account?
Anas Alamour
SOQL query to fetch new fields created this year with data types
I have requirment to run query to fetch new created fields this year in my org with the data type for each field. I run the following query , but the data type is not uncluded in the result :
SELECT id, DeveloperName, TableEnumOrId ,CreatedDate , CreatedById FROM CustomField WHERE CreatedDate = this_Year order by CreatedDate DESC
Any idea how to fetch the field data type in single query or using Apex code ?
Thanks.
SELECT id, DeveloperName, TableEnumOrId ,CreatedDate , CreatedById FROM CustomField WHERE CreatedDate = this_Year order by CreatedDate DESC
Any idea how to fetch the field data type in single query or using Apex code ?
Thanks.
You can get the all the standard and custom objects fields data types using the getGlobalDescribe, getDescribe, getType.
Reference:
https://salesforce.stackexchange.com/questions/15619/soql-query-by-data-type
https://salesforce.stackexchange.com/questions/264194/fetch-all-fields-whose-data-type-is-phone
Please mark as Best Answer if above information was helpful.
Thanks,
Thank you for your response on my question. Based on your provided apex code, i could write the follwing apex code and get all the custom picklist fields for all objects ( standard and custom ) :
Map<String,Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String,Schema.SObjectField> fieldMap;
for (String key: schemaMap.keyset()){
system.debug('The Object Name ='+ schemaMap.get(key));
fieldMap = schemaMap.get(key).getDescribe().fields.getMap();
for (String fieldName : fieldMap.keySet()) {
DescribeFieldResult dfr = fieldMap.get(fieldName).getDescribe();
if (dfr.getType() == Schema.DisplayType.picklist && dfr.isCustom())
{
System.debug('The Custom Picklist field Name ='+fieldName);
}
}
}
Just my remaining challange now is finding those fields created this year. I didn't find any method in DescribeFieldResult Class that returns the Createddate or LastModifieddate :
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_fields_describe.htm
https://ideas.salesforce.com/s/idea/a0B8W00000GdbhrUAB/createddate-and-lastmodifieddate-fields-in-apex-describe-methods
Please advise.
Thanks.