Apex レコードタイプIDを取得する方法

環境
Salesforce

構文
public ID getRecordTypeId()
このレコードタイプの ID を返します。

操作方法
1.オブジェクト名とレコードタイプ名を文字列で渡すだけでIDを取得する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public static Id getRecordtypeId(String objName,String developerName){
return Schema.getGlobalDescribe().get(objName).getDescribe().getRecordTypeInfosByDeveloperName.get(developerName).getRecordTypeId();
}
public static Id getRecordtypeId(String objName,String developerName){ return Schema.getGlobalDescribe().get(objName).getDescribe().getRecordTypeInfosByDeveloperName.get(developerName).getRecordTypeId(); }
public static Id getRecordtypeId(String objName,String developerName){
   return Schema.getGlobalDescribe().get(objName).getDescribe().getRecordTypeInfosByDeveloperName.get(developerName).getRecordTypeId();
 
}

2.レコードタイプIDの使い方
Id rsId = getRecordtypeId('Account’,’TestRecordType1′);

Apex

Posted by arkgame