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
rwalrath144rwalrath144 

My First Controller - Please review and assist with test method

I just finished my first controller class. I am creating a Customer Webform for customer's to fill in when they have issues with their orders. My first goal is to capture all these inquiries in a customer object called Email Log. I have already set up the object with all the necessary fields. To control the type of data the customer's fill in I have a few picklist fields with set values. For the purposes of this controller I am starting with a field called further_details__c. I was hoping somebody with more experience could look at my code and let me know if anything needs to be changed. I was also hoping to get some help with building a test method so I can deploy it.

 

public class WebformIssuesOptions {String[] further_details = new String[]{};

 

public PageReference test() {

return null;

}

 

public List<SelectOption> getItems(){

List<SelectOption> options = new List<SelectOption>();options.add(

new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country'));

options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue'));options.add(

new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate'));

options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date'));options.add(

new SelectOption('Order Inquiry','Order Inquiry'));

options.add(new SelectOption('Order Not Received','Order Not Received'));options.add(

new SelectOption('Order Placed from another Country','Order Placed from another Country'));

options.add(new SelectOption('Website Issues','Website Issues'));

return options;

}

 

public String[] getfurther_details(){ return further_details;

 

}

 

public void setfurther_details (String[] further_details){ this.further_details = further_details;

}

 

}

 

 

paul-lmipaul-lmi
please use the code button to post code, so it doesn't get all jumbled and is easier to read.
rwalrath144rwalrath144

Is this better:

 

public class WebformIssuesOptions { String[] further_details = new String[]{}; public PageReference test() { return null; } public List<SelectOption> getItems(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country')); options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue')); options.add(new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate')); options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date')); options.add(new SelectOption('Order Inquiry','Order Inquiry')); options.add(new SelectOption('Order Not Received','Order Not Received')); options.add(new SelectOption('Order Placed from another Country','Order Placed from another Country')); options.add(new SelectOption('Website Issues','Website Issues')); return options; } public String[] getfurther_details(){ return further_details; } public void setfurther_details (String[] further_details){ this.further_details = further_details; } }

 

DevAngelDevAngel

This seems pretty straight forward.  A test method might look like this:

 

 

public class WebformIssuesOptions {
String[] further_details = new String[]{};

public PageReference test() {
return null;
}

public List<SelectOption> getItems(){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country'));
options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue'));
options.add(new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate'));
options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date'));
options.add(new SelectOption('Order Inquiry','Order Inquiry'));
options.add(new SelectOption('Order Not Received','Order Not Received'));
options.add(new SelectOption('Order Placed from another Country','Order Placed from another Country'));
options.add(new SelectOption('Website Issues','Website Issues'));
return options;
}

public String[] getfurther_details(){
return further_details;

}

public void setfurther_details (String[] further_details){
this.further_details = further_details;
}

static testmethod void controllerTest() {
WebformIssuesOptions wio = new WebformIssuesOptions();
List<SelectOptions> options = wio.getItems();
System.assertEquals(options.size(), 8);

String[] details = new String[1];

details[0] = 'test';

wio.setFurther_Details(details);
System.assertEquals(wio.getFurther_Details[0], 'test');
}

}

 

 

rwalrath144rwalrath144

Thank you for the test code. It is really appreciated. However I am still running into errors.

 

For this code:

 

System.assertEquals(wio.getfurther_details[0], 'test');

 

I am getting this error:

 

Save error: Variable does not exist: getfurther_details 

 

I am also getting an error that states my test coverage is 73%.

chrismpls07chrismpls07
wio.getfurther_details[0] looks like you're attempting to refer to the variable further_details, which is not declared public. Call the getter and then refer to the array index - all you're missing is a pair of parentheses: wio.getfurther_details()[0]  should work.
Message Edited by chrismpls07 on 08-04-2009 02:42 PM