+ Start a Discussion
dhruv aroradhruv arora 

please help to write its test classtest class

Can someone help me to write test class for this code.

class----

public class MultiSelectCheckbox {

    public Opportunity opp{get;set;}
    
    public list<selectOption> MpOptions{get;set;}

    public MultiSelectCheckbox(ApexPages.StandardController controller) {
    
    opp= (Opportunity)Controller.getRecord();

    }
    
    public list<selectOption> MpOptions(){
    
    List<SelectOption> options = new List<SelectOption>();
    
    for(schema.pickListEntry f : opportunity.Multi_Select_Picklist__c.getDescribe().getPicklistValues())
    
    {
    options.add(new selectOption(f.getValue(),f.getLabel()));
    
    }
    return options;
    }
    
    
public string[] Checkbox{

get{

string[] selected = new list<string>();
list<selectOption> sos = this.MpOptions;
for(selectOption s :sos)
{

if(this.opp.Multi_Select_Picklist__c!=null && this.opp.Multi_Select_Picklist__c.contains(s.getValue()))
{
selected.add(s.getValue());
}
}
return selected;
}

set{

string selectedCheckBox='';
for(string s:value)
{
if(selectedCheckBox=='')
{
selectedCheckBox+=s;
}
else{selectedCheckBox+=';'+s;}
}
opp.Multi_Select_Picklist__c=selectedCheckBox;
}

}

}



vf page----



<apex:page standardController="opportunity" extensions="MultiSelectCheckbox">
  <apex:form >
  
  <apex:pageblock >
  
  
  <apex:pageblocksection >
  
  <apex:inputField value="{!opportunity.name}"/>
  <apex:inputField value="{!opportunity.closedate}"/>
  <apex:inputField value="{!opportunity.stagename}"/>
  
  
  </apex:pageblocksection>
  
  <apex:pageblocksection >
  
  <apex:inputField value="{!opportunity.Multi_Select_Picklist__c}"/>
  <apex:outputLabel value="{!$ObjectType.opportunity.Fields.Multi_Select_Picklist__c.InlineHelpText}"/>
  
  <apex:selectCheckboxes value="{!Checkbox}">
  
      <apex:selectOptions value="{!MpOptions}"/>
  
  </apex:selectCheckboxes>
  
  </apex:pageblocksection>
  
  <apex:pageblockbuttons >
  
  <apex:commandButton value="Save" action="{!Save}"/>
  </apex:pageblockbuttons>
  
  </apex:pageblock>
  </apex:form>
</apex:page>
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Dhruv, hope it will be helpful.​
  • Please mark it as best answer if it resolves your issue.
Thanks
Rahul Kumar