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
sandy hellosandy hello 

How to retrieve recordtypename for a record in befor update event dynamically with out SOQL

I nee a recordtypename for record in before update event dynamically without SOQL, based on recordtype name i will proces the record further.How can i achieve this.
CharuDuttCharuDutt
Hii Sandy
Try Below Code
Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Development').getRecordTypeId();


OR

trigger recordTypeCheck on objectName (before insert) { 
     for(objectName obj : trigger.new){ 
      if(obj.recordType.Name == 'RecordTypeAPI_Name' ) { 
         /*Your Code*/ 
    } 
  } 
}
Please Mark It As Best Answer If It Helps
Thank You!
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandy,

type with below code and modify according to your need.
trigger beforeupdateRecordtype on Account (before update) {
    
    for(Account acc: trigger.new)
        if(acc.recordtype.Name =='Customer Account'){
           // Proceed with fields you want to update 
        }

}

If this helps, Please mark it as best answer.

Thanks,
Ankaiah
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sandy,

You can use the below logic to get the record type name.
 
trigger AccountTrigerr on Account (before update) {

Map<ID, Schema.RecordTypeInfo> rtMap = Schema.SObjectType.Account.getRecordTypeInfosById();
    for(Account acc:Trigger.new){
        
        if(rtMap.get(acc.RecordTypeId).getName() =='merchant KYC Account'){
            acc.Rating='Hot';
            
        }
    }
}

If this solution helps, Please mark it as best answer

Thanks,
​​​​​​​