0

Hi I have difficulties with regards to custom settings, I have this field Type__c which has the data type 'text' and uses it in my visualforce. My field Type__c has 3 selections to choose inside the dropdown. Since the custom settings don't have the datatype Picklist, how can I create picklist selection on visualforce with a controller? i hope you'll help me.

<apex:outputLabel > Tyoe :</apex:outputLabel>
<apex:selectList size="1" >
    <apex:selectOption itemLabel="--None--" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Sandbox" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Production" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Developer" itemvalue=""></apex:selectOption>
</apex:selectList>

this is my save method

public PageReference save(){
        try{
            upsert orgInfo;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Created successfully'));
            ScheduledOrgInfoFetch.ScheduledOrgInfoFetch();
        }
        catch(System.DMLException e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Invalid Credentials'));
        }
            orgInfo = null;
            return null;  
    }
    enter code here
0

If you want to leverage picklist fields in your configuration records, you can use Custom metadata types. Its an alternative and better version of Custom Settings and support picklist fields.

If your uuse case doesnt allow you to use CMT, you can do the following to render a dropdown in the UI and save its value in apex class.

<apex:outputLabel > Tyoe :</apex:outputLabel>
<apex:selectList size="1" value="{!selectedType}">
    <apex:selectOption itemLabel="--None--" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Sandbox" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Production" itemvalue=""></apex:selectOption>
    <apex:selectOption itemLabel="Developer" itemvalue=""></apex:selectOption>
</apex:selectList>

In your apex class:

public String selectedType{get;set;}

public void MethodOfSave()
{
   CustomSettings__c cd = new CustomSettings__C();
   cd.Type__c = selectedType;
...
}

This should allow you to save the selected picklist value into Type__c field.

| improve this answer | |
  • i posted my save method where would i insert that one? – zane Sep 6 '18 at 6:47

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.