You need to sign in to do that
Don't have an account?
Bob DeRosier
Test class - Error Message System.NullPointerException: Attempt to de-reference a null object
The VF page works ok, I run into a problem on the test. My belief is that I am not feeding it the correct information.
Error Message System.NullPointerException: Attempt to de-reference a null object
Stack Trace Class.CateringReport_EventExtension1.<init>: line 115, column 1
Class.CateringReport_EventExtension1_Test.testclasses: line 26, column 1
The test code:
Error Message System.NullPointerException: Attempt to de-reference a null object
Stack Trace Class.CateringReport_EventExtension1.<init>: line 115, column 1
Class.CateringReport_EventExtension1_Test.testclasses: line 26, column 1
The test code:
@isTest public class CateringReport_EventExtension1_Test { private static region__c createRegion(){ region__c reg = new region__c (Name = 'XXX'); insert reg; return reg; } private static Event__c createEvent() { Event__c e = new Event__c( Start__c = Date.newinstance(2014, 1, 10), End__c = Date.newinstance(2014, 1, 13), region__c = [SELECT Id FROM Region__c WHERE Name = 'XXX'].Id ); insert e; return e; } @isTest static void testclasses(){ Event__c myEvent = new Event__c(); Test.setCurrentPageReference(new PageReference('Page.thePageName')); ApexPages.StandardController sc = new ApexPages.standardController(myEvent); CateringReport_EventExtension1 doPage = new CateringReport_EventExtension1(sc);
It fails at the line "Start = "
public CateringReport_EventExtension1(ApexPages.StandardController controller) { eventId = System.currentPageReference().getParameters().get('Id'); if (eventId != null && eventId != '') eventName = ([SELECT Name FROM Event__c WHERE Id = :eventId]).Name; // get location detail code from EventDetail_controller class hEvent = new haiEvent(eventId); event = (EventId == null) ? new Event__c() : hEvent.Event; // get location details if(event.Location__c != null) location = [SELECT Name, ZIP__c, Street__c, State__c, City__c, Google_Map_Url__c, Country__c, Small_Photo_URL__c FROM Location__c WHERE Id = :event.Location__c]; String tz = 'America/Los_Angeles'; if(event.Timezone__c != null) tz = event.Timezone__c; Start = event.Start__c.format('MMM d, yyyy h:mm a', tz); StartDate = event.Start__c.format('MMM d, yyyy', tz); EndDate = event.End__c.format('MMM d, yyyy', tz); getRegistrations(eventId); }
Below test class code should work: Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Error Message System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.CateringReport_EventExtension1_Test.createEvent: line 12, column 1
Class.CateringReport_EventExtension1_Test.testclasses: line 26, column 1