0

Am just wondering is there a way to saleforce provided libraries of schema/sobject to find name of a record type by pass in record Id in argmuments.

I am keen to find a way in which no soql is used hence. The library might use soql but this functionality can be embedded in a loop to get maximum output.

All ideas are welcome.

Till now I have reached a point where I can get to object record type but cheated as I hardcoded the object name but I was able to achieve this, but am wondering if a way is possible that I pass record Id and will get record type name out.

  • The solution has to be around custom object not Salesforce objects
3
  • 2
    You can use Id.getSObjectType() to get object type and use it with describe call to get the record type – Raul Mar 22 '19 at 1:15
  • AFAIK to get the recordtype for a specific record you will have to query for the record. If you just want all available types you can use above. Unless the record is part of a trigger then no need to query – Eric Mar 22 '19 at 4:35
  • Could you clarify if you want the record type of a specific record based on its Id, or a list of record types for the object of the record with a particular Id? – IllusiveBrian Mar 22 '19 at 20:14
0

As far as i know, you need to get this information through a query.

A possible solution would be to build a map or even a static map.

Map<Id, RecordType> mapRecordType = new Map<Id, RecordType>([Select Id, Name, ... FROM RecordType]);

This way once the map is initialized and loaded (used 1 SOQL query), you can access any RecordType in a loop very efficiently without any additional queries.

if(mapRecordType.containsKey([recordTypeId])
    String recordTypeName = mapRecordType.get([RecordTypeId]).Name;

I recommend you use RecordType.DeveloperName rather than RecordType.Name to ensure nothing breaks if someone changes the label but that is up to you.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.