[SalesForce] Query the created date of a custom field

I'm trying to do a large scale field cleanup within my org, and I'm looking to get a list of the custom fields by object (in this case the Account sobject), some basic details for those fields, and most importantly the created date of those fields. I cannot figure out how to get the created date though – which seems very odd.

Within the developer console, I'm using the Query Editor tab, and I'm entering in the following query:

SELECT QualifiedApiName, LastModifiedDate, DeveloperName, (Select DataType From Particles)
FROM FieldDefinition
WHERE EntityDefinition.QualifiedApiName ='Account'

I should note that I have the "Use Tooling API" checkbox enabled. If I enter in the CreatedDate attribute I get the following error back:

ERROR at Row:1:Column:44
No such column 'CreatedDate' on entity 'FieldDefinition'.

Can someone please point me in the right direction here? Seems very odd that I can't pull in the CreatedDate of a custom field, so I believe I'm doing something wrong.

Best Answer

The FieldDefinition table doesn't have a CreatedDate field, but CustomField does (but it's not in the documentation). It seems to me that you'll need to perform two queries and then match up the records by DeveloperName:

SELECT NameSpacePrefix, DeveloperName, TableEnumOrId, CreatedDate, LastModifiedDate FROM CustomField WHERE TableEnumOrId = 'Account'

Plus your original query. Note that DeveloperName won't include the __c, so you'll need to check the results from FieldDefinition to determine if it should be a custom field or not.

Related Topic