How to get RecordTypeName of an object in Salesforce.
Step 1:
Declare this like initialization parameter before any loop
Map<ID, Schema.RecordTypeInfo> recordTypeMap = Schema.SObjectType.Case.getRecordTypeInfosById();
Change the object accordingly.
Step 2 :
Get the Record type as String like below.
String recordtypeName = recordTypeMap.get(case.RecordTypeId).getName();
Full Example :
class {
List<Case> caseList = [Select id, name,status from case limit 100];
List<Case> toUpdate = new List<Case>();
Map<ID, Schema.RecordTypeInfo> recordTypeMap = Schema.SObjectType.Case.getRecordTypeInfosById();
for (Case c : caseList){
if(recordTypeMap.get(c.RecordTypeId).getName() == '*******'){
case cxUpdate = new Case();
cxUpdate.id = c.id;
cxUpdate.status = 'In Support';
toUpdate.add(cxUpdate);
}
update toUpdate;
}
}