You need to sign in to do that
Don't have an account?
Michael Haase
Nullpointer Exception when using custom settings in Apex Class (namespace prefix exists)
Hello all,
I get a nullpointer exeption when writing an apex class for my trigger. The apex class and the trigger use Custom Settings.I the rror: "System.NullPointerException: Attempt to de-reference a null object". I guess the reason is that the Custom Setting object cannot be correctly allocated due to the namespace prefix (M2809) I have registered.
Does anybody have an idea how to put that correctly in the code or how to solve the problem?
Here is the apex class. I get the error in line 7 column 0.
1 @isTest
2 public class TaskTriggerTest {
3 static testMethod void testLastResearchActivity_v2(){
4
5 //Get custom settings
6 Research_Mailer__c settings = Research_Mailer__c.getInstance('RMS');
7 String RSM_Task_Record_Type_ID = settings.m2809__Task_Record_Type_ID__c;
8 String RSM_ChuykoId = settings.Chuyko_Owner_ID__c;
9 String RSM_GoncharovId = settings.Goncharov_Owner_ID__c;
10 String RSM_ProfileId = settings.Profile_ID__c;
//Create 3 users and insert them
List<User> userToInsert = new List<User>();
//User 1
User u1 = new user();
u1.FirstName = 'David';
u1.LastName = 'Owner 1';
...
I get a nullpointer exeption when writing an apex class for my trigger. The apex class and the trigger use Custom Settings.I the rror: "System.NullPointerException: Attempt to de-reference a null object". I guess the reason is that the Custom Setting object cannot be correctly allocated due to the namespace prefix (M2809) I have registered.
Does anybody have an idea how to put that correctly in the code or how to solve the problem?
Here is the apex class. I get the error in line 7 column 0.
1 @isTest
2 public class TaskTriggerTest {
3 static testMethod void testLastResearchActivity_v2(){
4
5 //Get custom settings
6 Research_Mailer__c settings = Research_Mailer__c.getInstance('RMS');
7 String RSM_Task_Record_Type_ID = settings.m2809__Task_Record_Type_ID__c;
8 String RSM_ChuykoId = settings.Chuyko_Owner_ID__c;
9 String RSM_GoncharovId = settings.Goncharov_Owner_ID__c;
10 String RSM_ProfileId = settings.Profile_ID__c;
//Create 3 users and insert them
List<User> userToInsert = new List<User>();
//User 1
User u1 = new user();
u1.FirstName = 'David';
u1.LastName = 'Owner 1';
...
if Research_Mailer__c custom setting is heirerchy type please go and check default value or "RMS"( Profile,User) record exists if not then create default record or RMS
if it is List ty[e setting then create a new instance and insert new record
Karan
thats a good point. I will test that and let you know.
Thanks a lot so far.
Michael