You need to sign in to do that
Don't have an account?
test class - attempt to de-reference a null object
Hey guys... I'm geting really frustrated with having to test my classes... but *sigh* SF makes me do it anyways... Here's my problem:
I'm trying to test a page reference method that updates child records.
I've done the following:
It saves correctly, but when I run the test I get:
System.NullPointerException: Attempt to de-reference a null object
//Get back to the imaction Manager
PageReference refreshAxnMgr = new PageReference('/apex/IMACtionManager?id=' + thisImc.id);
Test.setCurrentPage(refreshAxnMgr);
//Instantiate and construct the controller class.
ApexPages.StandardController imcCon1 = new ApexPages.StandardController(new IMAC__c());
//extend controller with extension, referencing base controller
ImacController imcExt1 = new ImacController(imcCon1);
//Simulate the {!saveAXNS} expression in the Visualforce page
// by directly calling the saveAXNS method.
String saveAXNS = imcExt1.saveAXNS().getUrl(); <--dereferencing a null object (whatever that means)
//It should be back at the manager
System.assertEquals('/apex/IMACtionManager?id=' + thisImc.id, saveAXNS);
Here is the method Actual:
//Save function for IMACtions - used on IMACtions pageblock public PageReference saveAXNS() { try { update actions; } catch (Exception e) { ApexPages.addMessages(e); } return null; }
Thanks,
JN
Change your code to:
//Simulate the {!saveAXNS} expression in the Visualforce page
// by directly calling the saveAXNS method.
PageReference saveAXNS = imcExt1.saveAXNS(); <--dereferencing a null object (whatever that means)
//It should be back at the manager
System.assertEquals(null, saveAXNS);
All Answers
Change your code to:
//Simulate the {!saveAXNS} expression in the Visualforce page
// by directly calling the saveAXNS method.
PageReference saveAXNS = imcExt1.saveAXNS(); <--dereferencing a null object (whatever that means)
//It should be back at the manager
System.assertEquals(null, saveAXNS);
Ahh... Thanks!