function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SimrinSimrin 

geting recordType

Hello,

I have a field with type "Record Type".

How can i use it in SOQL query ?

recordType , recordTypeId didnt work
Best Answer chosen by Simrin
Amit Chaudhary 8Amit Chaudhary 8
You can get Record type By following ways :-

Option 1 :- You can check by record 

Select id,Name,recordTypeid,recordType.Name from Account limit 5;

Option 2 :- By Describe call 

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
List<Schema.RecordTypeInfo> RT = R.getRecordTypeInfos();
..............................

private String getRecordTypeSelectedId(String recordTypeName){
    String rtId;
    List<RecordType> rtList = New List<RecordType>([Select ID, Name From RecordType Where sObjectType = 'Work_Order__c']);
    for(RecordType rt : rtList) {
        if(rt.Name == recordTypeName) {
             rtId = rt.Id;
        }
    }
    return rtId;        
}

.........................

Option 3 :- Direct query record by SOQL

select id,name from recordType where SobjectType ='account';


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

 

All Answers

Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi Simrin,

There is no need to query. you can get the record type id using schema.

YOUR_OBJECT_API_NAME.sObjectType.getDescribe().getRecordTypeInfosByName().get('YOUR_RECORD_TYPE_NAME').getRecordTypeId()
Amit Chaudhary 8Amit Chaudhary 8
You can get Record type By following ways :-

Option 1 :- You can check by record 

Select id,Name,recordTypeid,recordType.Name from Account limit 5;

Option 2 :- By Describe call 

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
List<Schema.RecordTypeInfo> RT = R.getRecordTypeInfos();
..............................

private String getRecordTypeSelectedId(String recordTypeName){
    String rtId;
    List<RecordType> rtList = New List<RecordType>([Select ID, Name From RecordType Where sObjectType = 'Work_Order__c']);
    for(RecordType rt : rtList) {
        if(rt.Name == recordTypeName) {
             rtId = rt.Id;
        }
    }
    return rtId;        
}

.........................

Option 3 :- Direct query record by SOQL

select id,name from recordType where SobjectType ='account';


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

 
This was selected as the best answer