public class SchemaGlobalDescribe{
|
//idをもとに、オブジェクトAPI名を取得
|
public static String findObjectNameFromRecordIdPrefix(String recordIdOrPrefix){
|
String objectName = '';
|
try{
|
String myIdPrefix = String.valueOf(recordIdOrPrefix).substring(0,3);
|
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
|
for(Schema.SObjectType stype : gd.values()){
|
Schema.DescribeSObjectResult r = stype.getDescribe();
|
String prefix = r.getKeyPrefix();
|
if(prefix!=null && prefix.equals(myIdPrefix)){
|
objectName = r.getName();
|
break;
|
}
|
}
|
}catch(Exception e){
|
System.debug(e);
|
System.debug(Logginglevel.ERROR, e.getStackTraceString());
|
}
|
return objectName;
|
}
|
}
|