1

I've been searching around for a few hours for what I initially thought should be a very simple thing.

I want to write some Apex code that will iterate through all of the objects and fields in my org and check the Descriptions.

I can iterate through the objects and fields and get names, and other bits BUT NOT description. Is there any way to do this?

I want to create a test class that checks descriptions that were newly created (and eventually ALL descriptions) and checks to see that:

  1. they are not empty,
  2. they are comprised of more than just the field name,
  3. they are greater than a certain number of characters.

I want to do this to be able to enforce descriptions being filled in on creation of new fields. Nothing more frustrating than empty descriptions, or descriptions like this: Name of Field: "Do XYZ", description: "Does XYZ" ....aaarggh #$@##*&# !!!!!

1
  • I suspect there is no way to do this currently. If you look at the [documentation][1] for fields, you don't find description in there.
    – abhi
    Commented Aug 13, 2017 at 12:34

2 Answers 2

0

You could jump out to the Tooling API CustomObject and CustomField. You can do this with either SOAP or the REST API. For the latter there is an existing community wrapper project.

The SOQL queries could be as simple as:

Select Id,DeveloperName,Description from CustomObject
Select Id,TableEnumOrId,DeveloperName,Description from CustomField

Either way (SOAP/REST), this will cost you a Callout to get the data. Hence it won't be directly accessible in a Testing context. You would need to persist the data somewhere before running the test to make it accessible. At which point you would need to consider if the solution is starting to cause more problems than you started out with.


As an alternative, you could look at automating the check with something like the sfdx command line.

E.g. Get the list of custom objects in the org.

sfdx force:schema:sobject:list -c custom -u DevHub

Get the metadata for that custom object. In my case Fruit__c

sfdx force:schema:sobject:describe -s Fruit__c -u DevHub
1
  • sfdx .... theres a whole new world I have yet to dive into. Without having done any Google searches, Im assuming that the describe above returns an XML format back (or is it JSON or some other format). I take it that this is simply a command line way of achieving what the Developer Workbench and REST explorer describe calls do? Commented Aug 26, 2017 at 13:18
2

You cannot do this from within Apex today.

However, Salesforce is building Apex Metadata Api which should help building something like this possible. That api and its GA is still little far away.

The only option now is to develop an external tool to achieve this using Salesforce Metadata Api.

2
  • When you say that its still a little far away .... how far are we talking? Do you think it will come out in the next release (which is about what...two+ months away I think ) Commented Aug 26, 2017 at 13:16
  • Response from Salesforce at [success.salesforce.com/ideaView?id=08730000000l4TkAAI] indicates, it is scheduled to be released in Summer 17.
    – metasync
    Commented Sep 9, 2017 at 23:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .