+ Start a Discussion
Linga_RaminLinga_Ramin 

Can we remove values from PicklistEntry.If Yes then which method is used to remove values inside PicklistEntry

Best Answer chosen by Linga_Ramin
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="HidePicklistValueC">
    <apex:form>
        <apex:selectList title="PickList1" size="1" value="{!propPickValSelected}" styleClass="form-select">
            <apex:selectOptions value="{!PickLstValue}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

Controller:
public class HidePicklistValueC {
    
    Public string propPickValSelected { get; set; }
    
    public List<SelectOption> getPickLstValue() {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Account.Rating.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry f : ple) {
            if(f.getValue() != 'Hot') {
                options.add(new SelectOption(f.getLabel(), f.getValue()));
            }
        } 
        return options;           
    }
}

In for loop, you can check if the entry is the one you don't want.

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/forums/?id=906F0000000fxhfIAA

https://salesforce.stackexchange.com/questions/166987/display-specific-picklist-value-based-on-criteria

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="HidePicklistValueC">
    <apex:form>
        <apex:selectList title="PickList1" size="1" value="{!propPickValSelected}" styleClass="form-select">
            <apex:selectOptions value="{!PickLstValue}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

Controller:
public class HidePicklistValueC {
    
    Public string propPickValSelected { get; set; }
    
    public List<SelectOption> getPickLstValue() {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Account.Rating.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry f : ple) {
            if(f.getValue() != 'Hot') {
                options.add(new SelectOption(f.getLabel(), f.getValue()));
            }
        } 
        return options;           
    }
}

In for loop, you can check if the entry is the one you don't want.

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/forums/?id=906F0000000fxhfIAA

https://salesforce.stackexchange.com/questions/166987/display-specific-picklist-value-based-on-criteria

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
sfdc X-Mansfdc X-Man
Hi PMPR72
List<SelectOption> options = new List<SelectOption>(); 
Schema.DescribeFieldResult fieldResult = Account.Rating.getDescribe(); 
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); 
for(Schema.PicklistEntry f : ple) 
 { 
     if(!f.getValue().equalsIgnoreCase('Warm') && !f.getValue().equalsIgnoreCase('Hot') ) 
       { 
       options.add(new SelectOption(f.getLabel(), f.getValue())); 
     } 
} system.debug('options'+options);   

Please try this piece of code...
Thanks, sfdc x-man
Linga_RaminLinga_Ramin
Thanks Khan Anas that's worked for me