Last active
December 12, 2015 01:48
-
-
Save pcon/4693281 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Alternate way to get the name from a given Id | |
String objName = objId.getSObjectType().getDescribe().getName(); |
This file contains hidden or 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
/** | |
* Gets a map of the prefix for an object to the object name | |
* | |
* @return A map of id prefix to object name | |
*/ | |
public static Map<String, String> getObjectToPrefixMap() { | |
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); | |
Map<String,String> keyPrefixMap = new Map<String,String>{}; | |
Set<String> keyPrefixSet = gd.keySet(); | |
for(String sObj: keyPrefixSet){ | |
Schema.DescribeSObjectResult r = gd.get(sObj).getDescribe(); | |
String tempName = r.getName(); | |
String tempPrefix = r.getKeyPrefix(); | |
keyPrefixMap.put(tempPrefix,tempName); | |
} | |
return keyPrefixMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment