afawcett / apex-toolingapi

Apex wrapper for the Salesforce Tooling API
BSD 3-Clause "New" or "Revised" License
134 stars 98 forks source link

Reading Picklist information from CustomField does not return picklist info #27

Open afawcett opened 9 years ago

afawcett commented 9 years ago

This is actually a bug in the Tooling API itself rather than the wrapper, but logging here to discuss. I did some research over on this StackExchange answer here.

To test this i updated the ToolingAPIDemo class and output the JSON returned, also tested (as per StackExchange answer) in Workbench, the info is just not present, yet you get the corresponding number of pick list items.... :-1:

    public static void updatePicklist() {
        ToolingAPI toolingAPI = new ToolingAPI();

        // Query CustomObject object by DeveloperName (note no __c suffix required)
        List<ToolingAPI.CustomObject> customObjects = (List<ToolingAPI.CustomObject>) 
            toolingAPI.query('Select Id, DeveloperName, NamespacePrefix From CustomObject Where DeveloperName = \'Test\'').records;

        // Query CustomField object by Name (filtered by CustomObject Id)
        Id customObjectId = customObjects[0].Id;                            
        List<ToolingAPI.CustomField> customFields = (List<ToolingAPI.CustomField>) 
            toolingAPI.query('Select Id, DeveloperName, NamespacePrefix, TableEnumOrId, Metadata From CustomField Where TableEnumOrId = \'' + customObjectId + '\' And DeveloperName = \'YesNo\'').records;

        // Dump Picklist entries            
        for(ToolingAPI.PicklistEntry picklistEntry : customFields[0].metadata.picklist.pickListValues) {
            System.debug('Pick list label ' + picklistEntry.label);
        }

        // Next step would be to update pick list values and call the update Tooling API end point
        // ...
    }