Tuesday, April 29, 2014

Get Object Name of activity whatid

week before I came across the situation where task whoid and whatid are associated with many custom object and prob was how to find the object name. Object Name is required since when migrating task records then these object ids will change.

so below is the option i tried to get the Object name with objectPrefix values

String objPrefix  =  '800';              //replace this with your object first 3 digit

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType objectInstance : gd.values())
{
if(objectInstance.getDescribe().getKeyPrefix() == objPrefix )
{
System.debug('Object Name is: '+ objectInstance.getDescribe().getName());
}
}

No comments:

Post a Comment