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

How to retrieve Lead record type Name?

I'm trying to retrieve the record type Name of the Lead object in the following piece of code:
Lead objLead;
//constructor
        public LeadToMerchantController(ApexPages.StandardController controller) {    
                objLead = (Lead)controller.getRecord();
            }
        ...
            String leadType = objLead.RecordType.Name;
                    System.debug('leadType ' + leadType);

but instead I receive 'Null' as a value of 'leadType'.
Please advise how to retrieve the name of the Lead record type?
Best Answer chosen by sfadm sfadm
Arun MKArun MK
Hi,

The following worked fine for me.
public class testcontroller {
    Lead objLead{get;set;}
    
    public testcontroller(ApexPages.StandardController controller){
        objLead = (Lead)controller.getRecord();
        String leadRecType = objLead.RecordType.Name;
        system.debug('$$$$$'+leadRecType);
    }
}

Can you check if the recortypes are enabled for the lead in your org.

All Answers

Raj VakatiRaj Vakati
Looks like you are trying to create a new record. So records type is not available. 

Use SOQL query and set the values 
 String leadType = [Select Id,name From RecordType where sobjecttype = 'Lead' and Name = 'Training'].Name;


 
Arun MKArun MK
Hi,

The following worked fine for me.
public class testcontroller {
    Lead objLead{get;set;}
    
    public testcontroller(ApexPages.StandardController controller){
        objLead = (Lead)controller.getRecord();
        String leadRecType = objLead.RecordType.Name;
        system.debug('$$$$$'+leadRecType);
    }
}

Can you check if the recortypes are enabled for the lead in your org.
This was selected as the best answer