1

What is the best way to get the Record Type Description to display in a page?

    public class AccountRecordTypes {
    @AuraEnabled
    public static Map<String,String> GetAvailableRecordTypeAccount()
    {
        Map<String,String> recordTypeMap = new Map<String,String>();
        Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
        List<Schema.RecordTypeInfo> RT = R.getRecordTypeInfos();

       for( Schema.RecordTypeInfo recordType : RT )
    {
        if(recordType.isAvailable())
        { 
            if(recordType.Name!='Master') {
                recordTypeMap.put(recordType.getRecordTypeId(),recordType.Name);
            }
        }
    }


        }
        return recordTypeMap;
    }
}
5
  • So if I understand this correct, you are looking to get the "Description" of the Record Types available for a particular SObject, is that correct?
    – Jayant Das
    Commented Aug 31, 2018 at 17:51
  • Yes, but it seems that the getdescribe doesn't have the description
    – Cloud
    Commented Aug 31, 2018 at 17:52
  • Are you restricted to use describe apis here?
    – Jayant Das
    Commented Aug 31, 2018 at 17:52
  • no, i'm using the describe but it seems that the description is not available, since what I am going to display to may customize quick action is that an option to choose a record type with description
    – Cloud
    Commented Aug 31, 2018 at 17:53
  • Provided an approach as an answer, that should help you here.
    – Jayant Das
    Commented Aug 31, 2018 at 17:55

1 Answer 1

5

It seems that using RecordTypeInfo, you cannot actually get the Description field. So in that case, you can actually do a SOQL to get the record type details that you need.

Your query should look something as below:

SELECT Name, DeveloperName, Description FROM RecordType WHERE SobjectType = 'Account'

And once you get the results, you just construct the return data from your method. Your overall approach should look like this:

for(RecordType rec : [SELECT Name, DeveloperName, Description FROM RecordType WHERE SobjectType = 'Account']) {
    recordTypeMap.put(rec.Name, rec.Description);
}
8
  • do you have a sample link for me to follow thank you, yes, that's my option to make through soql
    – Cloud
    Commented Aug 31, 2018 at 17:59
  • You are looking for sample for what? How to construct the return data?
    – Jayant Das
    Commented Aug 31, 2018 at 18:22
  • yes, i'm looking for a sample
    – Cloud
    Commented Aug 31, 2018 at 18:42
  • I added that in the answer. But you should also look at how to fetch values from SOQL and use that in apex. Start with some trailhead, as this one
    – Jayant Das
    Commented Aug 31, 2018 at 18:50
  • Yes you are correct, apologies, I am having problem with displaying it on the page, i am new to lightning
    – Cloud
    Commented Sep 2, 2018 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .