You need to sign in to do that
Don't have an account?

How to Write a Test class for Picklist Entry? Using Schema
Hello, can you please help me on how to write a test class method for the ff. snippet below. I used schema to have my picklsit be dynamic in visual force page.
I need also the assertion. Thank you.
public List<SelectOption> getAccountTypeOptionsList(){ List<SelectOption> accountTypeOptionsList = new List<SelectOption>{new SelectOption('', '--None--')}; Schema.DescribeFieldResult accountTypeDescription = Account.Type.getDescribe(); List<Schema.PicklistEntry> accountTypePicklistValuesList = accountTypeDescription.getPicklistValues(); for(Schema.PicklistEntry accountTypePicklistValue : accountTypePicklistValuesList){ accountTypeOptionsList.add(new SelectOption(accountTypePicklistValue.getLabel(), accountTypePicklistValue.getValue())); } return accountTypeOptionsList; }
I need also the assertion. Thank you.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Controller:
Test Class:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Controller:
Test Class:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I replaced the class since it says invalid constructor Schema.Object. But I am still having an error inside the starttest() and stoptest(). My error says:
Error Message:
Method does not exist or incorrect signature: void getAccountTypeOptionsList() from the type List<System.SelectOption>
It won't recognize the class in my controller.
You need to use the correct class name.
Regards,
Khan Anas