Friday 17 August 2018

How to get Record Type developer name in Apex ?

Hi All,

Before summer 18, we used to write SOQL query to get developer name of a particular record type, now SOQL query is not required. 


This is my earlier post where recordtypeinfo method has been explained. What can we do using those methods.

https://salesforceworld4u.blogspot.com/2014/11/how-would-we-get-recordtype-id-and.html


1. How can we get Record Type Id of an object ?


    a.  Lets assume we know the record type name. say its "Inquiry".


Id objectRecordTypeId = Schema.SObjectType.CASE.getRecordTypeInfosByName().get('Inquiry').getRecordTypeId();
System.debug('objectRecordTypeId ---'+objectRecordTypeId ); 

    b.  Lets assume we know the record type developer name, say its "DevInquiry".


Id objectRecordTypeId = Schema.SObjectType.CASE.getRecordTypeInfosByDeveloperName().get('DevInquiry').getRecordTypeId();
System.debug('objectRecordTypeId ---'+objectRecordTypeId );

2.  How can we get record type developer name ? 


     a. Lets assume we know the record type name. say its "Inquiry".


String developerName = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Inquiry').getDeveloperName();

Same code can be broken into following.


String recordTypename = 'Inquiry';

Schema.DescribeSObjectResult caseDesribe = Schema.SObjectType.Case;
Map<String,Schema.RecordTypeInfo> rtMapByName = caseDesribe.getRecordTypeInfosByName();
Schema.RecordTypeInfo rtByName =  rtMapByName.get(recordTypename);
String RecordTypeDeveloperName = rtByName.getDeveloperName();
System.debug('RecordTypeDeveloperName --'+RecordTypeDeveloperName ); 

  b.  Lets Assume we know recordType id.


String developerName = Schema.SObjectType.Case.getRecordTypeInfosById().get('012w0000000kc2XAAQ').getDeveloperName();

Please let me know if you have any confusion, I would be happy to help.

Maintain Your Platform Developer I Certification for Summer ’18

10 comments:

Unknown said...

Best selenium online training institute `

unid said...

Thank you very much. I am about to write this post when doing code but I bump into this blog. I will my post and link to this later.

davidsmith said...

Salesforce Marketing Cloud Email Specialist dumps 2019 Actually its very nice site! this is my first visit on this site my friend gave the link of this site! and site is really great

Salesforce Developer said...

Thanks a lot for explaining practically. Really Appreciable!
Integrate Salesforce with third party software seamlessly and smoothly with the help of Atocloud.

unknown said...

Hiiii....Thank you so much for sharing Great information....Good post....Keep move on....
Best Salesforce Training Institutes in Hyderabad

saijitesh said...

Great information thank you so much, want to know more about Custom settings in Salesforce

high technologies solutions said...

Nice Post & I Must Say it is one of the best Blog I have every seen before Otherwise if anyone Want SALESFORCE Training with Placement So You Can Contact here-9311002620

Some Best SALESFORCE Training Center in Delhi, India

Salesforce training institute in delhi
Salesforce training institute in Noida
Salesforce training institute in Faridabad

Steve Jonas said...

Very nice and informative blog, Love reading your blogs.
check out this site too for Salesforce Development

Steve Jonas said...

Very nice and informative blog, Love reading your blogs.
check out this site too for Salesforce Development

Iqra technology said...

Very interesting article. Many articles I come across these days really not provide anything that attracts others, but believe me the way you interact is literally awesome.
salesforce support service
microsoft dynamic CRM
sharepoint development service
Magento e-commerce service
Power BI
RPA uipath
angular e-commerce