You need to sign in to do that
Don't have an account?
pradeep naredla
can any one help me to write test class for this class
---------------VfpageCode---------------
<apex:page standardcontroller="contact" extensions="sample123">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!layout}" value="layout" />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
<!------<apex:inputField value="{!Contact.Accountid}"></apex:inputField>----->
<apex:pageblockSectionItem >
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!state}">
<apex:selectOptions value="{!states}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!city}" id="a">
<apex:selectOptions value="{!cities}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
---------------ClassCode---------------
public class sample123
{
public sample123(ApexPages.StandardController controller)
{
}
public String state {get;set;}
public String city {get;set;}
public List<SelectOption> getStates()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('None','--- None ---'));
options.add(new SelectOption('TN','Tamil Nadu'));
options.add(new SelectOption('KL','Kerala'));
return options;
}
public List<SelectOption> getCities()
{
List<SelectOption> options = new List<SelectOption>();
if(state == 'TN')
{
options.add(new SelectOption('CHE','Chennai'));
options.add(new SelectOption('CBE','Coimbatore'));
}
else if(state == 'KL')
{
options.add(new SelectOption('COA','Coachin'));
options.add(new SelectOption('MVL','Mavelikara'));
}
else
{
options.add(new SelectOption('None','--- None ---'));
}
return options;
}
public PageReference layout() {
PageReference newPage;
if (city== 'CHE') {
newPage = Page.chennai;
}
if(city== 'CBE') {
newPage = Page.Coimbatore;
}
if(city== 'COA') {
newPage = Page.Coachin;
}
if(city== 'MVL') {
newPage = Page.Mavelikara;
}
return newPage.setRedirect(true);
}
}
<apex:page standardcontroller="contact" extensions="sample123">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!layout}" value="layout" />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
<!------<apex:inputField value="{!Contact.Accountid}"></apex:inputField>----->
<apex:pageblockSectionItem >
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!state}">
<apex:selectOptions value="{!states}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!city}" id="a">
<apex:selectOptions value="{!cities}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
---------------ClassCode---------------
public class sample123
{
public sample123(ApexPages.StandardController controller)
{
}
public String state {get;set;}
public String city {get;set;}
public List<SelectOption> getStates()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('None','--- None ---'));
options.add(new SelectOption('TN','Tamil Nadu'));
options.add(new SelectOption('KL','Kerala'));
return options;
}
public List<SelectOption> getCities()
{
List<SelectOption> options = new List<SelectOption>();
if(state == 'TN')
{
options.add(new SelectOption('CHE','Chennai'));
options.add(new SelectOption('CBE','Coimbatore'));
}
else if(state == 'KL')
{
options.add(new SelectOption('COA','Coachin'));
options.add(new SelectOption('MVL','Mavelikara'));
}
else
{
options.add(new SelectOption('None','--- None ---'));
}
return options;
}
public PageReference layout() {
PageReference newPage;
if (city== 'CHE') {
newPage = Page.chennai;
}
if(city== 'CBE') {
newPage = Page.Coimbatore;
}
if(city== 'COA') {
newPage = Page.Coachin;
}
if(city== 'MVL') {
newPage = Page.Mavelikara;
}
return newPage.setRedirect(true);
}
}
Refer below link to write the test class for controllers and extensions
https://salesforce.com/docs/developer/pages/Content/pages_controller_error_handling.htm
Try below code to test your extension
Mark this as "SOLVED" if your query is Answered
Regards,
Bhanu Mahesh