Skip to main content

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

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
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
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

Popular posts from this blog

Style in LWC

 Following are the ways we can apply in CSS in LWC. 1. Inline CCS Inline CSS is not recommended approaches, it is take highest priority among all CSS. style="color:green;font-size:10px;" is inline CSS added to div < template >     < lightning-card title = "Inline CSS" >         < div >             < div style = "color:green;font-size:10px;" > This is inline Style div </ div >         </ div >     </ lightning-card > </ template >  2. External CSS style can be applied to an elements such as h1, p,div span etc. It can applied to class using "." notation. for example .user{} It can also be applied to pseudo class.  for example .user:hover{} Id locator is not being used in LWC to apply style To apply external css, need to create separate CSS file, file name should be exactly matched with component name. for example - If component name is ...

How to Create/Delete file attachments(Content Document) through Apex ?

 There are 3 standard salesforce objects to store file attachments. Content Document, ContentDocumentVersion, ContentDocumentLink.  Here is the article to talk about these objects and relationship.  https://www.forcetalks.com/blog/contentdocument-and-contentversion-in-salesforce-an-overview/ ContentDocumentVersion ContentDocumentLink This post is all about how to create/delete content document though Apex. Here is code snippet // Insert Content Version record ContentVersion contentVersionRec = new ContentVersion(Title='filename',PathOnClient ='FileName.pdf',VersionData = bodyBlob,origin = 'H'); INSERT contentVersionRec; // this will insert one record in ContentDocument and ContentVersion , ContentDocument  is parent and  ContentVersion is child record // get contentdocument id contentVersionRec = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionRec .Id LIMIT 1]; // Create Content Document Link record- This will attach ...

Lifecycle hooks in LWC

There are 3 phase of LWC component  1. Mounting  A. constructor, B. connnectedCallback C. render D. renderedCallback 2. UnMounting  A. disconnectedcallback 3. Error  A.errorcallback Note - render is not lifecycle hook, it is protected method of Lightning element class. Mounting Phase LWC Creation and Render Life cycle Constructor Method ·        This method called when component is instantiated and It flows from parent to child component. ·        Need to call Super() inside constructor method ·        Can’t access any component properties or child component because it’s not ready yet. ·        Host element can be accessed through “this. template” inside constructor method. ·        Don’t add any attributes to host inside constructor C   constructor (){          super (); //...