How to Fetch Picklist value from sObject and Set in ui:inputSelect

Check Also : Lightning Web Component Version

Prerequisites : basic understanding of Lightning Component and apex programming

In this Sample code we will fetch Picklist field (‘Industry’) values from Account object and set in ui:inputSelect on lightning Component.

 

fetch picklist value and set in ui:inputSelect
output (click here to see full screen)
sample code for fetch Picklist values from sObject

apex class [ fetchPicklistOptsController.apxc ]

Component [sample.cmp]

Controller [ sampleController.js]

Helper [sampleHelper.js]

TestApp.app

Like our facebook page for new post updates.?

(Visited 65,975 times, 1 visits today)

45 thoughts on “How to Fetch Picklist value from sObject and Set in ui:inputSelect”

  1. Hiii Piyush soni,

    Thanks for your great post. I am looking same feature for last 2 days and finally i got this post.

    I need a help if you can please

    This is my task

    To get the pick list value
    1. Get the record type name of the related deal and then based on deal record type name load the investor__c record id.
    2. Based on record type id found in first step create an object of Investor__c object

     

    I need “Status” options list . How to i do this  (I have record type eg: ‘Financing’)

    Reply
  2. Hiii Piyush soni,

    Thanks for your great post. I am looking same feature with slight difference , i hope u ‘ll give best sol.

    i have 3 pick lists in my page , i have to fetch from custom object with where condition like

    1st pick list loads with employee names where from country UK, 2nd pick list loads with employee name where from country USA, like 3rd one also same with different country.

    Thanks In advance

    Reply
  3. Thank you for this awesome post ! I tried several solutions but yours is the best (and above all the best explaned one) . Thanks for sharing your knowledge. I’m a person who need to see concrete examples to understand and you saved me waaaaay more than several times 🙂

    Reply
  4. Hi,

    I tried the above code in my lightning component to fetch and update picklist values and it worked fine. But when I give it inside lightning tabset ‘<lightning:tabset >
    <lightning:tab >’, I am getting this error :

    ‘Uncaught Error in $A.getCallback() [Cannot read property ‘set’ of undefined]
    Callback failed: apex://NAT_RForceCases_VFC/ACTION$getselectOptions’. How to fix this?

    Thanks

    Aruna

    Reply
  5. HI! Everywhere I look online your code is the most popular. I am struggling a bit to understand what to change. I want to make it so that I can look up a picklist for a custom object for Client Payments (api would be Payment__c) and then I want to be able to choose the picklists in that custom object which would be things like Area of Concern, Organization… etc.

    Reply
  6. Hi, This post was very useful. Could you please let me know how to use lightning:select for the same example instead of ui:input

    Reply
  7. Thank you for the helpful post. Could you please let me know how to use lightning:select instead of inputselect for the same example.

    Reply
    • implementing the same in can be done this way.

      has attributes. we can use “value” attribute to dynamically populate values from the picklist of your choice. you can also use to place them on the page as explained in above piece of code. Thanks!

      Reply
  8. implementing the same in <lightning:select> can be done this way.

    has attributes. we can use “value” attribute to dynamically populate values from the picklist of your choice. you can also use <aura:iteration> to place them on the page as explained in above piece of code. Thanks!

    Reply
  9. Great post with solid example

    While this solution is working on desktop, on mobile, we have a small issue. In mobile, after the inout is selected, it doesn’t show the selected value until the cursor or current selection of field is moved to another field

     

    Reply
  10. Its a great code,

    Can you please let me know how I can get values form the Existing class, I am using force:recordData and I have few fields which has picklist already that i want to show when new record is getting created.

    Reply
  11. Hi,

    Please, anyone, help me for whenever select the picklist value show the help text message.

    How we can achieve this requirement.
    Example:

    Picklist values : A1,A2,A3,
    I need to the show help text selected value.

    Example : A1-Text1(Help text)

    A2-Text2(Help text)

    A3-Text3(Help text)

    Please provide me a solution.

    Thanks Advance,

    kiran

     

    Reply
  12. Hi piyush,
    I have tried this code to one picklistfield is fine but in the same component i tried to get one more picklistfield i am getting error.How to solve this problem

    Reply
    • Hi,

      I’m trying to do the same. Did you find a solution for this? I could add some more fields. But on the page, the values are not coming up in the fields, which was coming up before adding additional fields

      Reply
  13. Hi,

    If there are 2 or more record type of account and each record type has a different set of picklist values, how do you get the values of the picklist for a specific record type with this solution?
    I used the SOAP API for this but I want to know if there is a way to do it without doing callouts.

    Thanks!

    Reply
  14. Please help me as well, I need to populate the combobox with Objects dynamically and populate the next combobox with Object’s fields.

    Reply

Leave a Comment