You need to sign in to do that
Don't have an account?

Testing controller error Argument 1 cannot be null
Hi,
I'm new in salesforce, I code something that working well but I can't make working the test method. When I call the "iWantMyJSValues" function I've got "Argument 1 cannot be null".
public withsharingclass CourseController {
privatefinalCourse__c course;
private ApexPages.StandardController con ;
public CourseController(ApexPages.StandardController controller) {
con = controller;
this.course = (course__c)controller.getRecord();
}
public String valueOne { get; set; }
integer i;
public PageReference iWantMyJSValues() {
valueOne = Apexpages.currentPage().getParameters().get('one');
i = integer.valueof(valueOne);
if (i == 0) {
this.course.v_end__c = this.course.v_end__c + i;
} Else if (i == 1) {
this.course.v_start__c = this.course.v_start__c + i;
} Else if (i == 2) {
this.course.v_pause__c = this.course.v_pause__c + i;
}
update course;
returnnull;
}
public static testmethod void testiWantMyJSValues(){
list<Course__c> courses = newlist<Course__c>{};
Course__c testCourse = newCourse__c();
testCourse.Language__c = 'English';
testCourse.Training_Format__c ='On Demand';
testCourse. Course__c = 'a0Ea000000J0G1e';
courses.add(testCourse);
insert courses;
ApexPages.StandardController to = new ApexPages.StandardController(testCourse) ;
CourseController controller = new CourseController(to) ;
Controller.iWantMyJSValues();
}
}
Please add
Apexpages.currentPage().getParameters().put('one', '1');
line before you call
CourseController controller = new CourseController(to) ;
Controller.iWantMyJSValues();
in your test method.
All Answers
Take a look at the examples for testing a controller/page:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm
You aren't setting the page in your test method or parameters, so it has no idea what you're doing when you try to fetch page parameters.
Please add
Apexpages.currentPage().getParameters().put('one', '1');
line before you call
CourseController controller = new CourseController(to) ;
Controller.iWantMyJSValues();
in your test method.
It.s work thank you