function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VbourbeauVbourbeau 

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();

 

}

 

 

}

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma

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

dphilldphill

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.

Bhawani SharmaBhawani Sharma

Please add 

 

Apexpages.currentPage().getParameters().put('one', '1');

 

line before you call

 

CourseController controller = new CourseController(to) ;

Controller.iWantMyJSValues();

 

in your test method.

 

 

This was selected as the best answer
VbourbeauVbourbeau

It.s work thank you