Created
December 17, 2020 20:40
-
-
Save jmdohn/ad0b466a886c7edc9210b60a9044ef3e to your computer and use it in GitHub Desktop.
Sobject Description made easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String obj = 'PermissionSet'; | |
SObjectType r = ((SObject)(Type.forName('Schema.'+obj).newInstance())).getSObjectType(); | |
Map<String,Schema.SObjectField> fields = r.getDescribe().fields.getMap(); | |
for(String field : fields.keyset()){ | |
Integer padding = 50 - field.length(); | |
system.debug(fields.get(field) + '-'.repeat(padding) + fields.get(field).getDescribe().getLabel()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's fair - I wouldn't recommend using global describes in production-level code, typically (as I'm aware of the horrible performance); I thought this was just a helper method to be invoked on occasion in Anonymous Apex. If you're using globalDescribe to dynamically retrieve UI elements based on field names, or something, I definitely agree that it should be avoided like the plague due to the general slowness.