Search code examples
salesforceapexsoql

How to know who created a Field Set


I am currently unable to see who created a Field Set in Salesforce, I tried looking at the Schema.FieldSet class, but I couldn't find any details on createdBy

Map FsMap = Schema.SObjectType.Account.fieldSets.getMap();


Solution

  • Use a Tooling API query (from Developer Console, Workbench or another tool):

    SELECT Id, DeveloperName, Description, CreatedDate, CreatedBy.Name
    FROM FieldSet
    

    should get you started (in dev console it's just a matter of ticking the checkbox on bottom of query editor; in workbench go to REST explorer menu).

    https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_fieldset.htm


    Alternatively some info might be visible in Setup Audit Trail (last 6 months you can download easily, you can also query the table although it's painful to filter it... https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_setupaudittrail.htm


    EDIT

    There's not-exactly-documented way to know to which sObject this fieldset belongs. Documentation of Fieldset object doesn't mention the existence of EntityDefinitionId field but if you go to EntityDefinition in Tooling API you can see a very promising child relationship to Fieldsets. So... undocumented, can break in future but try this query

    SELECT EntityDefinitionId, EntityDefinition.Namespaceprefix, EntityDefinition.DeveloperName, 
        Id, DeveloperName, Description, CreatedDate, CreatedBy.Name
    FROM FieldSet
    ORDER BY EntityDefinitionId, Id
    

    Sample Tooling API query results for Fieldset + parent sObject