Search code examples
salesforceapexrecordtype

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


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.


Solution

  • 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);