Skip to content

Instantly share code, notes, and snippets.

@alex-shekhter
Last active June 6, 2017 03:32
Show Gist options
  • Save alex-shekhter/83ee08961bb293728d55275fd05d5546 to your computer and use it in GitHub Desktop.
Save alex-shekhter/83ee08961bb293728d55275fd05d5546 to your computer and use it in GitHub Desktop.
Get all SObject's prefixes in the Salesforce ORG. Better to be used like a SysAdmin.
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Map<String,String> objNameToPrefix = new Map<String,String>();
for ( Schema.SObjectType ot : gd.values() ) {
Schema.DescribeSObjectResult dor = ot.getDescribe();
objNameToPrefix.put( dor.getName(), dor.getKeyPrefix() );
}
System.debug( '--->>> ' + objNameToPrefix );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment