function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jon85943jon85943 

Creating Custom Picklist

I am relatively new to VF and am having trouble creating a custom picklist.  We created a page layout using VF and wanted to create a Record Type custom picklist, not using the standard picklist functionality.  I can't seem to get the code right, see below.  I have created an extention to try to create the custom list.

 

 

<apex:page standardController="Sharing_ES__c" extensions="RecordTypeExtension">
  <apex:form >
    <apex:sectionHeader title="{!$ObjectType.Sharing_ES__c.label}" subtitle="{!Sharing_ES__c.name}"/>
    <apex:pageBlock title="{!$ObjectType.Sharing_ES__c.label} Detail" mode="edit">
        <apex:pageBlockButtons >
      
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!edit}" value="Edit"/>
            <apex:commandButton action="{!delete}" value="Delete"/> 
            
        </apex:pageBlockButtons>
        <apex:pageBlockSection showHeader="false" columns="2">
            <apex:inputField value="{!Sharing_ES__c.Name}"/>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Custom Sharing Owner"/>
                <apex:outputPanel >
                    <apex:inputField value="{!Sharing_ES__c.OwnerId}"/>&nbsp;
                    <apex:outputLink value="{!URLFOR($Action.Sharing_ES__c.ChangeOwner,Sharing_ES__c.id)}">[Change]</apex:outputLink>
                </apex:outputPanel>
            </apex:pageBlockSectionItem>
       
            <apex:inputField value="{!Sharing_ES__c.Sharing_Type__c}"/>
            <apex:inputField value="{!Sharing_ES__c.Account__c}"/>
            <apex:inputField value="{!Sharing_ES__c.Access_Type__c}"/>
            <apex:inputField value="{!Sharing_ES__c.Description__c}"/>
            <apex:inputField value="{!Sharing_ES__c.User__c}"/>
            <apex:inputField value="{!Sharing_ES__c.Group__c}"/>
            <apex:pageBlockSectionItem />


<apex:pageBlockSection columns="1" showHeader="false">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RecordType" for="rtp"></apex:outputLabel>
                    <apex:selectList id="rtp" value="{!recordtype.id}" size="1" title="RecordType">
                        <apex:selectOptions value="{!rtp}"></apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

        </apex:pageBlockSection>
        <apex:pageBlockSection showHeader="false" columns="2">
            <apex:inputField value="{!Sharing_ES__c.CreatedById}"/>
            <apex:inputField value="{!Sharing_ES__c.LastModifiedById}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection showHeader="true" title="Custom Links" columns="3"> 
     </apex:pageBlockSection>
    
   </apex:pageBlock>
   </apex:form> 
 </apex:page>

 

 

 

And here is our Extension

 

 

public class RecordTypeExtension {
    private final RecordType r; //RecordType sObject
    
    //initializes the private member variable r by using the getRecord method from the standard controller
    public RecordTypeExtension(ApexPages.StandardController stdController) {
        this.r = (RecordType)stdController.getRecord();
    }
    
    //builds a picklist of Record Types for the SFL5_Project__c object
    public List<selectOption> getRecordType() {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below	
        for (RecordType rtp : [SELECT Id, Name FROM RecordType where SobjectType = 'SFL5_Projects__c']) { //query for Record Types
            options.add(new selectOption(rtp.ID, rtp.Name)); //for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }
}

 Thanks!

 

bob_buzzardbob_buzzard

There's a few issues that I can see.

 

1.  The standard controller for the page is for a Sharing_ES__c custom sobject.  Therefore the getRecord() call in your extension controller will return a Sharing_ES__c sobject, not a RecordType.  You probably want to retrieve the record type from the Sharing_ES__c object.

 

2. Your selectlist chosen value is backed by the property recordtype.id which doesn't exist in your controller.  As you have a method called getRecordType this adds to the confusion.

 

3. Your SelectOptions are backed by the property rtp which doesn't exist in your controller.  It looks like this should be backed by the getRecordType method to me.

 

 

 

 

 

ipsita.biswas@in.v2solutions.comipsita.biswas@in.v2solutions.com

Create a new String property named 'recordTypeId'

Rename the method 'getRecordType()' to 'getRecordTypeValues'

and replace this section

<apex:selectList id="rtp" value="{!recordTypeId}" size="1" title="RecordType">
                        <apex:selectOptions value="{!RecordTypeValues}"></apex:selectOptions>
                    </apex:selectList>