You need to sign in to do that
Don't have an account?
Sammy7
getting null pointer exception even with seealldate=true for test class on custom setting
Hi ,
I already have the custom setting in my sandbox org and my test class with seealldata=true. So why am I getting this:
EXCEPTION_THROWN|[33]|System.NullPointerException: Attempt to de-reference a null object
When I test the same EXACT test class in my developer org, I get 86% coverage. It drops to 21% in sandbox org....whats going on?
I already have the custom setting in my sandbox org and my test class with seealldata=true. So why am I getting this:
EXCEPTION_THROWN|[33]|System.NullPointerException: Attempt to de-reference a null object
When I test the same EXACT test class in my developer org, I get 86% coverage. It drops to 21% in sandbox org....whats going on?
Please see that the get method is case sensitive there is a difference in your query vs get method. In the query you are fetching value from custom setting with name 'Invoice_Template_id', where when you are using get methog for custom setting you are using 'Invoice_Template_Id'
Hope this helps. Please mark this thread as solved if this resolves your issue.
All Answers
Do you have data in the custom setting in your sandbox? If you have the data can you please share the line of code where you getting this exception.
Then here is my test class:
If you notice on line 32 of my controller, I put a check query and it returns this: 13:02:12:331 USER_DEBUG [32]|DEBUG|(Application_Properties__c:{value__c=0EHj0000000LWh4, Id=a07j000000J4xlQAAR})
But then on line 33, Im getting nullpointer exception on the same thing! How is this possible?
13:02:12:331 EXCEPTION_THROWN [33]|System.NullPointerException: Attempt to de-reference a null object
Please see that the get method is case sensitive there is a difference in your query vs get method. In the query you are fetching value from custom setting with name 'Invoice_Template_id', where when you are using get methog for custom setting you are using 'Invoice_Template_Id'
Hope this helps. Please mark this thread as solved if this resolves your issue.
String invoiceTemplateId =Application_Properties__c.getAll().get('Invoice_Template_Id').value__c
In the custom setting I have a record "Invoice_Template_id" with a value of 100
Like you mentioned in your custom setting you have a value for record "Invoice_Template_id"
If you see your code it says String invoiceTemplateId =Application_Properties__c.getAll().get('Invoice_Template_Id').value__c
Since custom settings getall().get method is case sensitive its throwing null pointer exception. (See the difference between lowercase id vs upper case Id in your code)