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

Strange issue with Apex Describe for RecordType

Hi All


I'm facing a strange issue.. Need your suggestions.


I have a trigger on Case which changes the recordtype when the case owner changes to a queue.


So i'm using below statement to get the recordtype id based on the name.


Schema.SObjectType.Case.getRecordTypeInfosByName().get('case record type').getRecordTypeId();


We have many profiles in our org , this statement is working for everyone except one profile.


As apex runs in system mode, i dont think recordtype access is an issue.

I tried using a query instead of above statement and it works even for this profile.


Recordtype temprectypeid=[Select Id from RecordType where name='case record type'];


I checked running the same statement in system log and getting null pointer exception where as for other profiles it works.


I tried comparing all the profile settings, every thing seems to be same.


Can any one help me debug the issue. I may be missing something.


Any pointers will be of great help






Can you try Id instead of the name to see if you are able to fetch the record. For example,


Recordtype temprectypeid=[Select Id from RecordType where Id='RecordTypeId'];


Of course, you will have to replace the "RecordTypeId" with the actual Id. Also it would be helpful to paste your code here to help you trouble shoot the issue. 


Thanks for the reply.


Query is working for me even with the name value.


Below statement has issues

Schema.SObjectType.Case.getRecordTypeInfosByName().get('case record type').getRecordTypeId();


This statement doesnt even work in sytem log for that particular profile.


I know you have probably answered this but I want to make sure that the permissions are correct.


a) You went to Setup | Administration Setup | Manage Users | Profule

 - Clicked on the profile and did not click edit.


b) Next > You scrolled to the Record Type section (Again the Profile is not in edit mode). And made sure the Record Type is selected for the object that is being accessed:


Image URL:

c) If you don't see the record type for the object here then click edit and add the record type for this profile. 


Lastly, if all of this is true then can you post your entire code to help you resolve this issue.