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
Santi Ram RaiSanti Ram Rai 

I have create one Property which gets the RecordType from object..

 Hi eveybody,

This is my Property in the apex class, which get the RecordType from the object. But it doesn`t work. Why? Please can you help me to fix it?
public List<String> ProjectRecordType{
    get {
        if (ProjectRecordType == null) {
    ProjectRecordType = new List<String>();
        Schema.DescribeFieldResult field = Project_Task__c.RecordType.Name.getDescribe();

         for (Schema.RecordTypeInfo rt: field.getType())
         ProjectRecordType.add(rt.getLabel());

        }
        return ProjectRecordType;          
    }
    set;
  }
}

 
pconpcon
Try the following
 
public List<String> ProjectRecordType {
    get {
        if (ProjectRecordType == null) {
            ProjectRecordType = new List<String>();
            Schema.DescribeSObjectResult r = Project_Task__c.SObjectType.getDescribe();
            
            for (Schema.RecordTypeInfo rt: r.getRecordTypeInfos())
                ProjectRecordType.add(rt.getName());
            
        }
        
        return ProjectRecordType;
    }
    set;
}

That is the preferred way [1] to get the record type informaiton.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_RecordTypeInfo.htm
Amit Chaudhary 8Amit Chaudhary 8
If you want to get the record type . Then please check below post. I hope that will help you
http://amitsalesforce.blogspot.in/2015/12/how-to-get-recordtypeid-without-soql.html
Id contRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('NameOfRecordType').getRecordTypeId();
Let us know if this will help you