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
ElectronElectron 

APEX code grant, and one error Attempt to de-reference a null object

Hi Bob and other contributor,

 

I faced one very weird question, that I can't understand. 

 

1. I know when we finished APEX Class, we must grant it in profile, then user could use it.

    But what about trigger? should we do same thing?

 

    Then here is my question.

 

2. I use one line code to help me get the Record Type

    it works fine in my side, of course I am Administrator. 

Id ID = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Customer').getRecordTypeId();   

 

    But when I tested with other standard user, question came.     

    No matter what kind contact editing, salesforce keep throwing the error 

 Attempt to de-reference a null object

   the error occurred right in previous line. 

 

3. My first understand 

  

    I just feel when trigger is triggered, the user will execute  the action( is this right?)

    

    Then normal user doesn't have the enough permission to execute the piece of Code. 

    So I got the error. 

 

4. Then I tested another trigger, who use same code to get Record Type ID.

     but nothing wrong, that make me very confused.

 

update 2013-05-15

      

     I was wrong, this code still doesn't work for normal user.

 

     Also I have other limitation, such like field checking to limite the trigger action, but why this error stop every editing, it doesn't make sense!

 

5. To fix it, I take replace of the previous code to another Query, like below

Id Id = [SELECT id from RecordType where Name ='Customer'].Id;

    Then nothing error message came up.

 

    So Salesforce, are you kidding me? what's the point, I really don't get it.

 

 

Sorry for my dramatic tone, it took me so long time, I really feel bad for it, is there someone could answer my question?

Best Answer chosen by Admin (Salesforce Developers) 
ElectronElectron

I can't tell the real reason, but I found out that normal user doesn't have enough permission to execute the Get Record Type method.

 

To avoid the error, you should use SOQL again(that's Sad)

All Answers

ElectronElectron

I saw one friend replied, thank you for that, but unfortuantely, that seems not the right solution for it. 

ElectronElectron

I can't tell the real reason, but I found out that normal user doesn't have enough permission to execute the Get Record Type method.

 

To avoid the error, you should use SOQL again(that's Sad)

This was selected as the best answer