Return to Snippet

Revision: 30205
at August 10, 2010 03:45 by d3developer


Initial Code
#
         * This method accepts the ID of any object type and returns the full name, including prefix of the sObject
#
         * type to which it belongs.
#
         * @author cpeterson
#
         **/
#
        public static Schema.SObjectType getObjectType(id subject){
#
                Schema.SObjectType result;
#
                string target = subject;
#
                Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
#
                string keyPrefix;
#
               
#
                for(Schema.SObjectType describe: gd.values() ){
#
                        keyPrefix = describe.getDescribe().getKeyPrefix();
#
                        if(keyPrefix != null && target.startsWith(keyPrefix)){
#
                                result = describe;
#
                                break; //no need to keep looking
#
                        }
#
                }
#
                return result;
#
        }

Initial URL

                                

Initial Description

                                

Initial Title
@ca_peterson SObject initialization from Id

Initial Tags

                                

Initial Language
Other