{"id":6877,"date":"2017-08-22T00:11:27","date_gmt":"2017-08-22T04:11:27","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6877"},"modified":"2019-08-08T00:21:06","modified_gmt":"2019-08-08T04:21:06","slug":"get-picklist-values-in-apex","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/get-picklist-values-in-apex\/","title":{"rendered":"Get Picklist Values in Apex"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/very-useful-tips-and-tricks-of-the-apex-salesforce-interview-questions-part-4\/\">Interview question part 4<\/a>, we discussed how <strong>dynamic Apex<\/strong> can be used to retrieve metadata information about Objects or fields on Object. <\/p>\n\n\n\n<p class=\"justify\">While writing highly configurable code, there are situation where we want to avoid hardcoding picklist values and read it realtime from field.<\/p>\n\n\n\n<p class=\"justify\">Below code snippet takes two parameter, Object and picklist field name. On basis of these two inputs, we can read either Picklist label or Picklist value (API Name)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nString objectName = &#039;Contact&#039;;\nString fieldName =&#039;LeadSource&#039;;\n  \nSchema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ;\nSchema.DescribeSObjectResult r = s.getDescribe() ;\nMap&lt;String,Schema.SObjectField&gt; fields = r.fields.getMap() ;\nSchema.DescribeFieldResult fieldResult = fields.get(fieldName).getDescribe();\nList&lt;Schema.PicklistEntry&gt; ple = fieldResult.getPicklistValues();\nfor( Schema.PicklistEntry pickListVal : ple){\n    System.debug(pickListVal.getLabel() +&#039; &#039;+pickListVal.getValue());\n}    \n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Code snippet of reading Picklist values in Salesforce Apex<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[337,471,232],"class_list":["post-6877","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-apex","tag-code-snippet","tag-dynamic-apex"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":6252,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-path-read-only-lightning-component\/","url_meta":{"origin":6877,"position":0},"title":"Salesforce Path &#8211; Read Only Lightning Component","author":"Jitendra","date":"September 17, 2017","format":false,"excerpt":"Chevron Component build in Lightning with Same look and feel as of Salesforce Path in read only mode","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Read only Path (Chevron) Component in Salesforce Lightning","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Chevron-Lightning-Component-Salesforce.gif?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5949,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/state-country-picklist-in-salesforce-supporting-alpha-3-iso-code\/","url_meta":{"origin":6877,"position":1},"title":"State &#038; Country picklist in Salesforce supporting Alpha-3 ISO code","author":"Jitendra","date":"March 22, 2017","format":false,"excerpt":"How to use Integration Value in State & Country picklist in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"State & Country Picklist in Salesforce","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/03\/State-Country-Picklist-in-Salesforce-1024x299.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/03\/State-Country-Picklist-in-Salesforce-1024x299.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/03\/State-Country-Picklist-in-Salesforce-1024x299.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/03\/State-Country-Picklist-in-Salesforce-1024x299.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5070,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/dependent-picklist-in-salesforce-flow-using-custom-metadata-type-video\/","url_meta":{"origin":6877,"position":2},"title":"Dependent picklist in Salesforce flow using Custom Metadata type &#8211; Video","author":"Jitendra","date":"December 7, 2015","format":false,"excerpt":"Salesforce flow is great alternative for Visualforce pages used by admin. I have written, multiple blog post on Salesforce flow already and in this post we will discuss how we can create dependent picklist in Flow. If you are already using flow, might know that creating dependent picklist is not\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce flow - Dependent picklist output","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/12\/Salesforce-flow-Dependent-picklist-output.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":4942,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-winter-16-top-features\/","url_meta":{"origin":6877,"position":3},"title":"Salesforce Winter 16 &#8211; Top features","author":"Jitendra","date":"October 28, 2015","format":false,"excerpt":"You can watch recording of my live stream channel as well to know more on Winter 16 features.\u00a0Powerpoint presentation used in livestream can be accessed from here. 1. Object Manager Objects are objects, even if they are standard or custom objects. Salesforce simplified navigation to access Objects, we can access\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Setup Audit Trail - Salesforce Winter 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4967,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-flow-interview-questions-for-admins-part-23\/","url_meta":{"origin":6877,"position":4},"title":"Salesforce Flow Interview Questions for admins &#8211; Part 23","author":"Jitendra","date":"December 7, 2015","format":false,"excerpt":"\ufeff Consider it interview questions or FAQs, However below are some high level information or gotchas related to Salesforce Flow. 221. How to create lookup field in Salesforce flow? Ans : There is no direct way to create a lookup field in flow but we can use workaround mentioned in\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Sample Salesforce flow using loop element","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/Sample-Salesforce-flow-using-loop-element.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/Sample-Salesforce-flow-using-loop-element.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/Sample-Salesforce-flow-using-loop-element.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3278,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/visualforce\/using-fieldset-with-visualforce-and-apex\/","url_meta":{"origin":6877,"position":5},"title":"Using FieldSet with Visualforce and Apex","author":"Jitendra","date":"May 3, 2013","format":false,"excerpt":"One of the disadvantages comes up with Custom Page or Overriding New or Edit button with Visualforce page is its \"Maintenance\"\u009d, if New Filed is Added or needed to remove field we have to modify our code every time. However, Thanks to Salesforce that we have \"Field Set\"\u009d. With the\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Create Field Set in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=6877"}],"version-history":[{"count":2,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6877\/revisions"}],"predecessor-version":[{"id":6879,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6877\/revisions\/6879"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}