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
sandeshdsandeshd 

displaying all the picklist values through visualforce page irrespective of record type

We have a requirement where we need to access all the picklist values  through a visual force page irrespective of the record type.

Hereis the sample code :

 

<apex:page standardController="Opportunity">

<apex:form>

<apex:InputField value = "{!Opportunity.DeliveryInstallationStatus__c}"/>

</apex:form>

</apex:page>

 

It is displaying only the picklist values  of my default record type. I want all the picklist values of that field. 

 

Please let me know how  to achieve that...

bob_buzzardbob_buzzard

One way to achieve this is to create your own selectlist that contains each value from the picklist.  You can create a selectoption per picklist value as follows - this assumes the object is called My_Custom__c and the field is Status__c

 

      List<SelectOption> statusOptions=new List<SelectOption>();
      Map<String, Schema.SObjectType> gd=Schema.getGlobalDescribe();
      Schema.SobjectType sso=gd.get('My_Custom__c');
      Schema.DescribeSobjectResult dsr=sso.getDescribe();
      Map<String, Schema.SObjectField> fieldMap=dsr.fields.getMap();
      Schema.SObjectField statField=fieldMap.get('Status__c');
      
      Schema.DescribeFieldResult fieldDesc = statField.getDescribe();
      List<Schema.PicklistEntry> plEntries = fieldDesc.getPicklistValues();
           
      for (Schema.PickListEntry plEntry : plEntries)
      {
          SelectOption option=new SelectOption(plEntry.getValue(), plEntry.getLabel());
          statusOptions.add(option); 
      }
 

 

sandeshdsandeshd

Thank you but cant we achieve it using input field itself. As I can see this behaviour in one of our sandboxes but the developer who has developed that has left the company and we are not sure of how he did it. The same piece of code is displaying all the picklist values in one sand box and in the other sandbox it is displaying only the picklist values available for the default record type. We tried hard but we couldnt figure it out . We compared the values available to the record types in both the sand boxes and other comparisions. They are both same but still I see they are behaving differently in two different sandboxes.  Is there any config or admin change which will allows to take all the picklist values .  They must have done some thing special to over come the recordtype restriction. pls suggest.

 

 

SalesRedSalesRed

Hi Bob, I hope you're well.

 

I was wondering, for the process outllined below do you know if it's still the best approach or as it was from 2011, if a more up-to-date approach would be better?  Also using the approach provided,   if I debug "statField.getDescribe()" the following is returned

 

Schema.DescribeFieldResult[getByteLength=240;getCalculatedFormula=null;getController=null;getDefaultValue=null;getDefaultValueFormula=null;getDigits=0;getInlineHelpText=null;getLabel=Billing Country;getLength=80;getLocalName=BillingCountry;getName=BillingCountry;getPrecision=0;getRelationshipName=null;getRelationshipOrder=null;getScale=0;getSoapType=STRING;getSobjectField=BillingCountry;getType=STRING;isAccessible=true;isAutoNumber=false;isCalculated=false;isCaseSensitive=false;isCreateable=true;isCustom=false;isDefaultedOnCreate=false;isDependentPicklist=false;isDeprecatedAndHidden=false;isExternalId=false;isFilterable=true;isGroupable=true;isHtmlFormatted=false;isIdLookup=false;isNameField=false;isNamePointing=false;isNillable=true;isPermissionable=true;isSortable=true;isUnique=false;isUpdateable=false;isWriteRequiresMasterRead=false;]

 

however fieldDesc.getPicklistValues() is empty.

 

Could there be a setting which affects returning picklist values to an apex class?

 

Thanks in advance.