Assume 'Supplier' is the recordtype in Account Object as shown in image below.
If you want to get that supplier record type id in apex,We need to first prepare a map of all recordtypes of that account object and then get our required record typeid from it.
Sample Code:
Map <String,Schema.RecordTypeInfo> recordTypeMap = Account.sObjectType.getDescribe().getRecordTypeInfosByName();
Account accountObj = new Account();
accountObj.name = 'Test Record Type';
if(recordTypeMap.containsKey('Supplier')) {
accountObj.RecordTypeId= recordTypeMap.get('Supplier').getRecordTypeId();
}
insert accountOb;
system.debug('CreatedAccountId'+accountObj.id);
Output :
If you want to get that supplier record type id in apex,We need to first prepare a map of all recordtypes of that account object and then get our required record typeid from it.
Sample Code:
Map <String,Schema.RecordTypeInfo> recordTypeMap = Account.sObjectType.getDescribe().getRecordTypeInfosByName();
Account accountObj = new Account();
accountObj.name = 'Test Record Type';
if(recordTypeMap.containsKey('Supplier')) {
accountObj.RecordTypeId= recordTypeMap.get('Supplier').getRecordTypeId();
}
insert accountOb;
system.debug('CreatedAccountId'+accountObj.id);
Output :
Hi, I was wondering if we can just read it directly like in
ReplyDeleteSupplier_RecTypeId = [SELECT Id FROM RecordType WHERE name = 'Supplier' and isActive = true LIMIT 1];