Activity Forums Salesforce® Discussions what is list used for in salesforce?

  • Mohit

    Member
    January 6, 2017 at 3:09 pm

    Hi Sushant,

    The List<SelectOption> is used to show the dynamic drop-down value on the visualforce page.

    For Eg:-

    Apex Controller:-

    public class sampleCon {

    String[] countries = new String[]{};

    public PageReference test() {
    return null;
    }

    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('US','US'));
    options.add(new SelectOption('CANADA','Canada'));
    options.add(new SelectOption('MEXICO','Mexico'));
    return options;
    }

    public String[] getCountries() {
    return countries;
    }

    public void setCountries(String[] countries) {
    this.countries = countries;
    }

    }

    Visualforce Page:-

    <apex:page controller="sampleCon">
    <apex:form>
    <apex:selectCheckboxes value="{!countries}">
    <apex:selectOptions value="{!items}"/>
    </apex:selectCheckboxes><br/>
    <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>
    <apex:outputPanel id="out">
    <apex:actionstatus id="status" startText="testing...">
    <apex:facet name="stop">
    <apex:outputPanel>
    <p>You have selected:</p>
    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
    </apex:outputPanel>
    </apex:facet>
    </apex:actionstatus>
    </apex:outputPanel>
    </apex:page>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos