You need to sign in to do that
Don't have an account?
Suman Bonthala
public class controllerActionSupport{
public string accid {get; set;}
public List<Contact> SelectedAcc{get;set;}
public list<selectoption> getaccountnames() {
list<selectoption> accoptions = new list<selectoption>();
accoptions.add(new selectoption('None', '--Select Account--'));
for (account acc : [select id, name from account]){
accoptions.add(new selectoption(acc.id, acc.name));
}
return accoptions;
}
public void getDetails() {
SelectedAcc = new List<Contact>();
SelectedAcc = [SELECT id, FirstName, Email FROM Contact WHERE AccountId=:accid ];
}
}
how to write test for custom controller
public class controllerActionSupport{
public string accid {get; set;}
public List<Contact> SelectedAcc{get;set;}
public list<selectoption> getaccountnames() {
list<selectoption> accoptions = new list<selectoption>();
accoptions.add(new selectoption('None', '--Select Account--'));
for (account acc : [select id, name from account]){
accoptions.add(new selectoption(acc.id, acc.name));
}
return accoptions;
}
public void getDetails() {
SelectedAcc = new List<Contact>();
SelectedAcc = [SELECT id, FirstName, Email FROM Contact WHERE AccountId=:accid ];
}
}
Below will cover your class.
I would suggest you to go through these links to understand more about the testclasses.
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
Hope you would go through the above mentioned links , to learn about the testclasses :)
We make some changes in your custom-controller and write the test class for the controller and it covers 100% test coverage in my ORG.
Try the following class and test-class it may be helpful for you:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Try this test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi