0

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.

Method----------------------

    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);
            bUSet.add(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'){
                    strSelected='All';

                }
                else if(obj.Business_Unit__r.ProjectType__c=='Project'){
                    strSelected='-None-';
                }
            }

            return options;
        }

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

<apex:form >
  <br/>
    <apex:outputpanel>
    <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"/>
        </apex:selectList>
        <br/><br/>
        </apex:outputpanel>

 </apex:form>
  • 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) – Sebastian Kessel Dec 10 '15 at 14:57
  • ProjectType__c is the Record type – Tinkerbell Dec 10 '15 at 14:59
  • ProjectType__c has different record type values – Tinkerbell Dec 10 '15 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? – Sebastian Kessel Dec 10 '15 at 15:01
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.