I'm trying to find out the recordType Name/Id based on the record Id.
Id myid = 'a1aV0000003DzYE';
String sObjectType = ((Id)myid).getSobjectType().getDescribe().getName();
//finding recordtype Name/Id ?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI'm trying to find out the recordType Name/Id based on the record Id.
Id myid = 'a1aV0000003DzYE';
String sObjectType = ((Id)myid).getSobjectType().getDescribe().getName();
//finding recordtype Name/Id ?
Use following methods to get recordtype Name or Id based on the parameters passed to these methods.
public static Id getRecordTypeIdbyName(String objectName, String strRecordTypeName)
{
return Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfosByName().get(strRecordTypeName).getRecordTypeId();
}
public static String getRecordTypeNameById(String objectName, Id strRecordTypeId)
{
return Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfosById().get(strRecordTypeId).getName();
}
Update
You need to query RecordTypeId through SOQL based on recordId.
SELECT Id, RecordtypeId, RecordType.name FROM Account where Id = '<your id>';