Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Contact Us
    • Discussions
    Close search
    Retrieve picklist value of a record type using MetaData Service in Salesforce

    Retrieve picklist value of a Record Type using MetaData Service in Salesforce

    Parul Sep 10, 2018
    43,714  Views

    Picklist values are able to see using standard UI of sObject then field name and then record type name. What if we want to see these picklist values using a Visualforce page.

    Here is the solution to this situation using the Metadata Service Class. By using this class we can get sObject as metadata object and retrieve its recordtype, list of picklist values or particular picklist values.

    So how to enable this functionality in Salesforce? Just follow the steps : –

    1. Create a Remote Setting which holds URL of your org

    Firstly, search for Remote site setting in the Quick Find box.

    Now click on New Remote Site

    Now Enter details of the Remote site setting, in which Remote Site URL is your instance from the URL.

    For example: https://*********-dev-ed—c.ap4.visual.force.com

    2.Set Session Settings to “Lock session to the domain in which they were first used”

    3. Write a Metadata Service class which is used to get dependent picklist values on the basis of record type.

    Here is the code snippet:

    Apex Controller:

    public class retrievePicklistValueofRecordType(){
         public String objectName{get;set;}
         public String recordTypeName{get;set;}
         public String fieldName{get;set;}
         public List<String> listofValue{get;set;} 
         public retrievePicklistValueofRecordType() { 
             objectName = ”; 
             recordTypeName = ”; 
             fieldName = ”; 
             listofValue = new List<String>(); 
         }     
         public void retrieveValue(){       
             listofValue=MetadataServiceExamples.getDependentPicklistValuesByRecordType(objectName,recordTypeName,fieldName);
         }
    }

    Metadata Service Class:

    public with sharing class MetadataServiceExamples {
        public static List<String> getDependentPicklistValuesByRecordType(String objectName,String recordTypeName,String fieldName){
            List<String> listofavailablevalue = new List<String>();
            String objectRecordType = objectName + '.' + recordTypeName;
            // Create serviceMetadataService.MetadataPort service = createService();
            MetadataService.RecordType recordType = (MetadataService.RecordType) service.readMetadata('RecordType', new String[] { objectRecordType }).getRecords()[0];
            for ( MetadataService.RecordTypePicklistValue rpk : recordType.picklistValues ) {
                if ( rpk.picklist == fieldName ) {
                    for ( MetadataService.PicklistValue pk : rpk.values ) {
                        listofavailablevalue.add(String.valueof(pk.fullName));
                    }
                }
            }
            return listofavailablevalue;
        }
    }
    public MetadataService.IReadResult readMetadata(String type_x,String[] fullNames) {
          MetadataService.readMetadata_element request_x = new MetadataService.readMetadata_element();
          request_x.type_x = type_x;request_x.fullNames = fullNames;
          MetadataService.IReadResponseElement response_x;
          Map<String, MetadataService.IReadResponseElement> response_map_x = new Map<String,MetadataService.IReadResponseElement>();
          response_map_x.put('response_x',response_x);
          WebServiceCallout.invoke(this,request_x,response_map_x,new String[ { 
    endpoint_x,'','http://soap.sforce.com/2006/04/metadata','readMetadata','http://soap.sforce.com/2006/04/metadata','readMetadataResponse','MetadataService.read' + type_x + 'Response_element'});
          if(!Test.isRunningTest()){
              return response_x.getResult();
          }
          else {
              MetadataService.IReadResult obj;return obj;
          }
    }

    Here is the Picklist value: List of Picklist value

    Particular Picklist value:

    Hope this will help you.

    Thanks.

    Categories: Others
    Tagged: Callout, List in Salesforce, Lock Session, Metadata, Metadata Service Class, Picklist Values, Quick Find Box, Remote Setting, Salesforce Code, Salesforce Fields, Salesforce Org, Salesforce Record, Salesforce sObject, Session Settings, SOAP, Visualforce, Web Services

    Get listed your company

    Have an innovative Salesforce solution that delivers faster, smarter results?
    Join the Marketplace

    [adinserter block=”16″]

    best salesforce consultants
    best salesforce consultants
    best salesforce consultants
    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants
    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants
    salesforce consultants
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.