I got the following method and vf page. I got a object called Business_unit and it has two record types (Business Unit and Project).

I got a SelectOptions List, and I want to make the selectoption values default to 'All' when Record Type is 'Business Unit' -when user creates a new Business Unit record.

Also I want to make the selectoption values default to '-None-' when Record Type is 'Project' -when user creates a new 'Project' type Business Unit record. currently my code always defaults to '-None-' in both record types.


    public List<SelectOption> getPortfolioProjectRecords(Id currentBusinessUnitId){

            grc__Business_Unit__c theBusinessUnit = SoqlHelper.getBusinessUnit(currentBusinessUnitId);

            // Ensure only risks for the business unit and the BU children are listed
            Set<grc__Business_Unit__c> bUSet = BusinessUnitHelper.getChildBusinessUnits(theBusinessUnit);

            //String strSelected;
            strSelected = '';
            options = new List<SelectOption>();

            for(Business_Unit_Project_Portfolio_Lookup__c obj :[SELECT Id, Name, Business_Unit__c, Business_Unit__r.ProjectType__c, Project_Portfolio__c, Project_Portfolio__r.Name FROM Business_Unit_Project_Portfolio_Lookup__c WHERE Business_Unit__c IN: bUSet AND (Business_Unit__r.ProjectType__c = 'Business Unit' OR Business_Unit__r.ProjectType__c = 'Project')] ){
            options.add(new SelectOption(obj.Project_Portfolio__c,obj.Project_Portfolio__r.Name)); 

                if(obj.Business_Unit__r.ProjectType__c=='Business Unit'){

                else if(obj.Business_Unit__r.ProjectType__c=='Project'){

            return options;

VF page------------------------

<apex:form >
    <b><apex:outputLabel value="Select Portfolio"/></b> &nbsp;&nbsp;
        <apex:selectList value="{!strSelected}" multiselect="false" size="1">
            <apex:selectOption itemValue="All" itemLabel="All" />
            <apex:selectOption itemValue="-None-" itemLabel="-None-" />
            <apex:selectOptions value="{!options}"/>
            <apex:actionSupport event="onchange" action="{!portfolioList}" reRender="drawHeatmap"/>

  • Your code is currently using "ProjectType__c" for this. Do you wish to replace this with the recordType of the Business_unit__c object? (Just to confirm) Dec 10, 2015 at 14:57
  • ProjectType__c is the Record type
    – Tinkerbell
    Dec 10, 2015 at 14:59
  • ProjectType__c has different record type values
    – Tinkerbell
    Dec 10, 2015 at 15:00
  • RecordType is a standard field, and it represents a standard feature within the salesforce interface (help.salesforce.com/HTViewHelpDoc?id=customize_recordtype.htm). Do you mean to ask to change the default value of the picklist based on the value of the "ProjectType__c" field? Dec 10, 2015 at 15:01

1 Answer 1


The way I see it, your code is iterating on each Business_Unit_Project_Portfolio_Lookup__c and changing the "strSelected" every time (depending on the record being iterated). The way your code is written, the value will always be identical to the last record to be iterated. I would suggest code changes, but I can't quite follow the intent of the code as is.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .