[SalesForce] How to find current record’s RecordType name

I have a requirement where I have to write some logic in an Opportunity Trigger.

Requiremnt is , I have find out current opportunity's record type and have to check whether that recordtype name contains some value or not.

Is there any way to find out the current opportunity record's Recordtype Name ?

I found 1 useful link:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Schema_RecordTypeInfo.htm

But, confused how to use that in my logic.

Best Answer

If you are doing this in the trigger it would be something like this:

trigger OnOpportunity on Opportunity(before update){

     Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById();

     for(Opportunity opp : trigger.new){

          if(rt_map.get(opp.recordTypeID).getName().containsIgnoreCase('YOUR VALUE')){
               //Do your stuff
          }

     }


}