How to get all RecordType names as list of string in salesforce

160 Views Asked by At

I am trying to retrieve names of all the RecordTypes of Account Object in salesforce. I am getting error with the soql query. I found this query on the web.

strQuery = 'SELECT Name, SobjectType FROM RecordType WHERE SobjectType=\'Account\'';
        List<RecordType> lstRecordType = Database.query(strQuery);

This is returning a RecordType list. How I can get the names of the recordType only.

1

There are 1 best solutions below

0
eyescream On BEST ANSWER

Loop through them? ;)

List<String> names = new List<String>();
for(RecordType rt : [SELECT Name FROM RecordType WHERE SobjectType='Account']){
    names.add(rt.Name);
}
System.debug(names);