You need to sign in to do that
Don't have an account?
VF Test Class - Add option to multiselect picklist and returned selected
Hi All,
Hope someone could help me! I have written a test class but it only has 25% code coverage and upon checking on Developer Console, the part of my class that is not yet covered is the function that makes a multi-select picklist field appear as a checkbox on my visualforce page. As of now I don't have any idea on how I can add multiselect picklist values to display and get the selected value on the test class. Can someone please help me on this? Thank you!
Test Class: -
PageReference pageRef2 = Page.DD_SurveyFormENNoimeTYPage;
Test.setCurrentPage(pageRef2);
//i have 2 more landing pages that gets selected based on the value placed on language__c hidden field on VF page
//how do i add an if to set pageref2 value based on the value on language__c
PageReference pageRef1 = Page.DD_SurveyFormEN_Noime;
Test.setCurrentPage(pageRef1);
ApexPages.currentPage().getParameters().put('id',c.id);
ApexPages.StandardController dc = new ApexPages.StandardController(sf);
DerekSurveyFormNoime JobExCon = new DerekSurveyFormNoime(dc);
//how to display here the options for multiselect picklist and return selected option
JobExCon.savesf();
Here is the part of my class that converts multiselect picklist to a checkbox: -
public List<SelectOption> MPOptions {
get {
List<SelectOption> options = new List<SelectOption>();
for( Schema.PicklistEntry f : DD_Survey_Form__c.What_is_your_preferred_commucation__c.getDescribe().getPicklistValues()) {
options.add(new SelectOption(f.getValue(), f.getLabel()));
}
return options;
}
set;
}
public String[] MPItems {
get {
String[] selected = new List<String>();
List<SelectOption> sos = this.MPOptions;
for(SelectOption s : sos) {
if (this.sf.What_is_your_preferred_commucation__c !=null && this.sf.What_is_your_preferred_commucation__c.contains(s.getValue()))
selected.add(s.getValue());
}
return selected;
}public set {
String selectedCheckBox = '';
for(String s : value) {
if (selectedCheckBox == '')
selectedCheckBox += s;
else selectedCheckBox += ';' + s;
}
sf.What_is_your_preferred_commucation__c = selectedCheckBox;
}
}