Record Type from apex in Salesforce

The usual way to get a recordTypeId in Apex is to make a query like this:

[Select id from RecordType where sObjectType = 'XXXXX' and developerName ='YYYYY' ].id

XXXXX = SobjectType (object name)

YYYYY = Record Type Name (DeveloperName)


Example :

class AccountHelper
{
 
     public static String personRecordTypeId;
     public static String getPersonRecordTypeId(){
            
     if(AccountHelper.personRecordTypeId == null) 
     {
         AccountHelper.personRecordTypeId =[Select id from RecordType where sObjectType = 'Account'    and developerName ='Person Account' ].id
      }
           
      return AccountHelper.personRecordTypeId ;
}

Comments

Popular Posts