function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RonSFRonSF 

Find a specific record Type

Hi
How can I recognize a specific record Type. Requirement is that when there is a record Type A then put a validation on a field. But how can I recognize a recordtype by its name such as A in this case. I was doing some in the below lines and obviously it does not work as 3rd statement is incorrect. Can anyone please point out something
List<Object> items
          for(Object item : items)
             if(item.RecordTypeId.getName().equals('A')){   //DOES NOT WORK
                    if(item.B == null){
                       do stuff
                    }
                }
       }
Hargobind_SinghHargobind_Singh
Can you try using item.RecordTypeName and see if that works ? 
 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi RonSF,

Please try below code .
Id aRecordTypeId = Schema.SObjectType.YOUR_OBJECT_API_NAME.getRecordTypeInfosByName().get('A').getRecordTypeId();

List<Object> items
          for(Object item : items)
             if(item.RecordTypeId == aRecordTypeId){   //DOES NOT WORK
                    if(item.B == null){
                       do stuff
                    }
                }
       }
Let us know if it helps you.
 
Patcs_1Patcs_1

Hi

Hope this code will help!

 Map<ID,RecordType> rt_map = New Map<ID,RecordType>([Select ID, Name From RecordType Where sObjectType = 'case']);

     for(case c : items){

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

     }

RonSFRonSF
I went ahead with Patcs_1 solution and it seems working fine and looks like responses from Ashish and Hargobind will work as well. I will write some tests to ensure the functionality. Really appreciate all your responses on the query. Thanks