[Salesforce]オブジェクトのレコードタイプIDからレコードタイプ名取得

オブジェクトのレコードタイプIDからレコードタイプ名取得例を紹介します。

  List<RecordType> recordTypeList = [
    SELECT Id
      , Name
      FROM RecordType
      WHERE SobjectType = 'testObj__c'
      AND Id = '012211111111111111'
  ];

for(RecordType rtobj : recordTypeList){
    system.debug('rtobj.Name:'+rtobj.Name);
}

または、以下の例もあります。

String searchObjName = 'testObj__c';
String searchRecordTypeId = '012211111111111111';
List<RecordType> recordTypeList = [
    SELECT Id
      , Name
      FROM RecordType
      WHERE SobjectType  = : searchObjName
      AND Id = : searchRecordTypeId
  ];

for(RecordType rtobj : recordTypeList){
    system.debug('rtobj.Name:'+rtobj.Name);
}

[Salesforce]Failed to run tests synchronously.: Your query request was running for too long.

テストクラス実行時、「Failed to run tests synchronously.: Your query request was running for too long.」エラーの対応

Summary
Test classes failing with QUERY_TIMEOUT Failed to run tests synchronously when running in synchronous mode

  1. Login to the org which has quite number of managed package apex classes.
  2. Run the Apex Test Class from Developer Console in Sync Mode
  3. You may notice below exception when running the apex test class:

Error Message:

“QUERY_TIMEOUT Failed to run tests synchronously: Your query request was running for too long”

Workaround
As a workaround, please try to run the test class in asynchronous mode.