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
Anshul Kapoor 13Anshul Kapoor 13 

How to get the pick list values dynamically as per record type

Hi,

How to get the pick list values dynamically using record type- 
Below is the code- 

vf Page-

<apex:selectList id="countries" value="{!Office_Location__c.Country__c}"
         size="1" required="true">
  <apex:selectOptions value="{!countries}"/>
</apex:selectList>


public List<SelectOption> getCountries()
{
  List<SelectOption> options = new List<SelectOption>();
        
   Schema.DescribeFieldResult fieldResult =
 OfficeLocation__c.Country__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        
   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }       
   return options;
}

I have 2 record types - Scanback & AutoBill & field country having different values as per record Type.
Best Answer chosen by Anshul Kapoor 13
sfdcMonkey.comsfdcMonkey.com
hi Anshul,
Currently we can't access picklist values based on Recordtype in Apex code, please refer the idea 
https://success.salesforce.com/ideaView?id=08730000000gNpLAAU.
If picklist values for record type are properly set you just have to use <apex:inputField /> tag. 

i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks 
sfdcmonkey.com 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi Anshul,
Currently we can't access picklist values based on Recordtype in Apex code, please refer the idea 
https://success.salesforce.com/ideaView?id=08730000000gNpLAAU.
If picklist values for record type are properly set you just have to use <apex:inputField /> tag. 

i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks 
sfdcmonkey.com 
This was selected as the best answer
Anshul Kapoor 13Anshul Kapoor 13
Thanks @piyush_soni
Anshul Kapoor 13Anshul Kapoor 13
@piyush_soni

Ur answer is the best Answer :)