You need to sign in to do that
Don't have an account?
Alx Mr
Test apex controller get method
Good day,
I need help writing tests for my get methods. I'm quite a newbie. May you give a pice of advise or a snipet, please.
the apex controller code:
Visual force code
I need help writing tests for my get methods. I'm quite a newbie. May you give a pice of advise or a snipet, please.
the apex controller code:
public SelectOption[] getSubGroupsMulti() { aGroupId = (ApexPages.currentPage().getParameters().containsKey('groupId')? ApexPages.currentPage().getParameters().get('groupId'):null); SelectOption[] lSO_subGroups = new SelectOption[]{}; strSubGroups = [select Sub_Group__c from Account where Id = :aGroupId].Sub_Group__c; arrSubGroups = strSubGroups.split(';'); for (integer i=0; i<arrSubGroups.size(); i++) { lSO_subGroups.add(new SelectOption(arrSubGroups[i], arrSubGroups[i])); } return lSO_subGroups; }
Visual force code
<apex:selectList value="{!aSubGroups}" size="1" multiselect="false"> <apex:selectOptions value="{!SubGroupsMulti}"/> </apex:selectList>Thank you very much
Take a look over this article [1] and it should get you down the right path. If you have any problems with writing the test, please include what you have here and we'll be happy to help you.
It's important to note that you don't specifically reference anything in your Visualforce page when testing your controller. You call the methods directly.
[1] https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm
My most recent try is posted above. By this i got code coverage of 3 lines 2-4. the 3 parameters needed to rerender the the page.
now i have no clue how to test the split of string into array, and populating the select option list.
I think a have to mention before get method i declared the following variables variable:
public Id aManagerId {get; set;}
public Id aId {get; set;}
public Id aGroupId {get; set;}
public string aSubgroups{get;set;}
public String strSubGroups;
public String[] arrSubGroups;
Thank you for any help.