Showing posts with label Get the Record Type Id of any object with out querying it in Trigger or Apex Class. Show all posts
Showing posts with label Get the Record Type Id of any object with out querying it in Trigger or Apex Class. Show all posts

Wednesday, May 18, 2011

Salesforce – Get the Record Type Id of any object with out querying it in Trigger or Apex Class


Solution Approach – We need to use describe SObject for this.
Sample Code  -
        //To get the record Type Id for Account – Record Type Name is “Person Account”
                
                    //Get all the Record Types of Account and store it in a map.
    Map <String,Schema.RecordTypeInfo> recordTypes =        Account.sObjectType.getDescribe().getRecordTypeInfosByName();
 
     //Get the record type id of from the Map based on the Name
    Id RecTypeId = recordTypes.get('Person Account').getRecordTypeId());