Tag Archives: Record Type

Retrieve the Record Type Which are Accessible by User’s Profile only

The below code will add only the record type of “Contact” object accessible to the user.

List <SelectOption> rtList = new List <SelectOption>();
for (RecordTypeInfo rtInfo: Contact.SObjectType.getDescribe().getRecordTypeInfos() ) {
	if(rtInfo.isAvailable()) {
		rtList.add(new SelectOption(rtInfo.getRecordTypeId(), rtInfo.getName()));
	}
}

Add Record Type in Test Class

Sample Code:

@isTest()
public class TestUtils {
    
    private static testmethod  void CreateAccount(){
        //Get Account Record Type Id
        Id accountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('DeveloperNameOfRecordType').getRecordTypeId();
        
        //Create Account
        Account acc = new Account();
        acc.Name ='Test Account';
        acc.Industry = 'Retail';
        acc.AccountNumber = '123456';
        acc.RecordTypeId = accountRecordTypeId;
        Insert acc;
    }
}