How to Identify SobjectType Dynamically in Apex

Here is a script that answers your How to Identify SobjectType Dynamically in Apex getKeyPrefix of Schema.getGlobalDescribe can be used to identify dynamically the SobjectType in Apex. String prefix = recordId.substring(0,3); String objectType; Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); for(Schema.SObjectType s : gd.values()){     if(prefix == s.getDescribe().getKeyPrefix()){         objectType = s.getDescribe().Name;     } } recordId consists […]