Retrieve picklist values dynamically of Opportunity Object without apex class using ‘uiObjectInfoApi’ property and displaying the selected pick-list value in Salesforce Lightning Component — LWC | How to fetch picklist value without apex method and display selected pick-list value in lwc

13,622 views

Hey guys, today in this post we are going to learn about how to Retrieve picklist values dynamically of Opportunity Object fields of StageName without apex class using ‘uiObjectInfoApi’ property and displaying the selected pick-list value in Salesforce Lightning Component — LWC.

Here we Use the wire adaptor to get the picklist values for a specified field of Opportunity.

Picklist values are scoped to a record type. For dependent picklists, getPicklistValues returns data for controlling fields and map to the picklist.

To retrieve all picklists of a record type, use getPicklistValuesByRecordType. To know more, click here

Why Should You Schedule Meeting?

🎯 If You Are Facing Any Of These 6 Challenges. Schedule Meeting With Me.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 

Files we used in this post example

picklistValueLWC.html Lightning Web Component HTML Template HTML file for used to write HTML element for display the picklist of opportunity stage name.
picklistValueLWC.js LWC JavaScript File It is holding @Wire method function that is fetching the picklist value from database using uiObjectInfoApi.
picklistValueLWC.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as like lightning__AppPage, lightning__RecordPage, lightning__HomePage..

Final Output

fetch picklist values based on record type in salesforce lwc -- w3web.net

 

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

  • Find the below steps

Create Lightning Web Component HTML

Step 1:- Create Lightning Web Component HTML ➡ picklistValueLWC.html

SFDX:Lightning Web Component ➡ New ➡ picklistValueLWC.html

picklistValueLWC.html [Lightning Web Component HTML]

  1.    <template>
  2. <lightning-card title="Get picklist values of StageName field from Opportunity " icon-name="standard:opportunity">
  3.  
  4.     <div class="slds-m-around_medium">
  5.  
  6.         <template if:true={OpportunityPicklist.data}>
  7.  
  8.             <lightning-combobox name="StageName" label="Stage Name" value={StageValue}
  9.  
  10.                 options={OpportunityPicklist.data.values} onchange={handleChange}>
  11.  
  12.             </lightning-combobox>
  13.  
  14.         </template>        
  15.  
  16.  
  17.         <template if:true={Prospecting}>
  18.  
  19.            <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  20.             <div class="slds-page-header__name-title">
  21.                 <h4 class="slds-page-header__title">                
  22.                     <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  23.                 </h4>
  24.             </div>
  25.             <br/> 
  26.                <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  27.                <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  28.             </div>    
  29.         </template>
  30.  
  31.         <template if:true={Qualification}>
  32.  
  33.             <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  34.                 <div class="slds-page-header__name-title">
  35.                     <h4 class="slds-page-header__title">                
  36.                         <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  37.                     </h4>
  38.                 </div>
  39.                 <br/> 
  40.                    <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  41.                    <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  42.                 </div>
  43.         </template>
  44.  
  45.         <template if:true={NeedsAnalysis}>
  46.             <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  47.                 <div class="slds-page-header__name-title">
  48.                     <h4 class="slds-page-header__title">                
  49.                         <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  50.                     </h4>
  51.                 </div>
  52.                 <br/> 
  53.                    <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  54.                    <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  55.                 </div>
  56.         </template>
  57.  
  58.         <template if:true={ValueProposition}>
  59.             <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  60.                 <div class="slds-page-header__name-title">
  61.                     <h4 class="slds-page-header__title">                
  62.                         <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  63.                     </h4>
  64.                 </div>
  65.                 <br/> 
  66.                    <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  67.                    <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  68.                 </div>
  69.         </template>
  70.  
  71.         <template if:true={IdDecisionMakers}>
  72.             <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  73.                 <div class="slds-page-header__name-title">
  74.                     <h4 class="slds-page-header__title">                
  75.                         <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  76.                     </h4>
  77.                 </div>
  78.                 <br/> 
  79.                    <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  80.                    <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  81.                 </div>
  82.         </template>
  83.  
  84.         <template if:true={PerceptionAnalysis}>
  85.             <div style="background:#ddd; border:1px #ccc solid; padding:10px; margin-top:10px;"> 
  86.                 <div class="slds-page-header__name-title">
  87.                     <h4 class="slds-page-header__title">                
  88.                         <lightning-icon icon-name="standard:opportunity" size="small"></lightning-icon> Selected value is:- <span style="color:#ff8000; font-size:18px;">{StageValue}</span> 
  89.                     </h4>
  90.                 </div>
  91.                 <br/> 
  92.                    <p>This is default description of <strong style="color:brown">{StageValue} ..</strong></p><br/>
  93.                    <p><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> w3web.net</a> is the place where you can learn step-by-step about Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, JavaScript, Jquery, CSS, Configuration, Customization, Development and much <a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"> more…</a></p>
  94.                 </div>
  95.         </template>
  96.  
  97.     </div>
  98. <br/><br/>
  99.    <!--Start RelatedTopics Section-->
  100. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  101.  
  102.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  103.  
  104.             <br/><br/>
  105.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  106.             <div style="display:block; overflow:hidden;"> 
  107.                 <div style="width: 50%; float:left; display:inline-block">
  108.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  109.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  110.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  111.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  112.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  113.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  114.                     </ul>
  115.             </div>
  116.  
  117.             <div style="width: 50%; float:left; display:inline-block">
  118.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  119.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  120.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  121.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  122.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  123.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  124.                     </ul>
  125.                 </div>
  126.                <div style="clear:both;"></div> 
  127.                <br/>
  128.                 <div class="youtubeIcon">
  129.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  130.                 </div>
  131.     </div>
  132.  
  133. </div>
  134.  
  135.   <!--End RelatedTopics Section-->
  136.  
  137.    </lightning-card> 
  138. </template>
  139.  
  140. </lightning-card>
  141. </template>

Create Lightning Web Component Javascript

Step 2:- Create Lightning Web Component Javascript ➡ picklistValueLWC.js

SFDX:Lightning Web Component ➡ New ➡ picklistValueLWC.js

picklistValueLWC.js [LWC JavaScript File]

  1.    import { LightningElement, wire, api, track } from 'lwc';
  2.  
  3. import { getObjectInfo } from 'lightning/uiObjectInfoApi';
  4.  
  5. import { getPicklistValues } from 'lightning/uiObjectInfoApi';
  6.  
  7. import Opportunity_OBJECT from '@salesforce/schema/Opportunity';
  8.  
  9. import StageName_FIELD from '@salesforce/schema/Opportunity.StageName';
  10.  
  11.  
  12. export default class PicklistValueLWC extends LightningElement {
  13.     StageValue ='';
  14.     Prospecting= '';
  15.     Qualification = '';
  16.     NeedsAnalysis = '';
  17.     ValueProposition = '';
  18.     IdDecisionMakers = '';
  19.     PerceptionAnalysis = '';
  20.  
  21.     // getting the default record type id, if you dont' then it will get master
  22.  
  23.     @wire(getObjectInfo, { objectApiName: Opportunity_OBJECT })
  24.  
  25.     opportunityMetadata;
  26.  
  27.     // now retriving the StageName picklist values of Opportunity
  28.  
  29.     @wire(getPicklistValues,
  30.  
  31.         {
  32.  
  33.             recordTypeId: '$opportunityMetadata.data.defaultRecordTypeId', 
  34.  
  35.             fieldApiName: StageName_FIELD
  36.  
  37.         }
  38.  
  39.     )
  40.  
  41.     OpportunityPicklist;
  42.  
  43.     // display the selected picklist value
  44.  
  45.  
  46.     handleChange(event) {
  47.  
  48.         this.StageValue = event.detail.value;
  49.         this.picklistVal = this.StageValue;
  50.        if(this.picklistVal === 'Prospecting'){
  51.           this.Prospecting = this.StageValue ;
  52.        }else{
  53.         this.Prospecting = '';
  54.        }
  55.  
  56.        if(this.picklistVal === 'Qualification'){
  57.          this.Qualification = this.StageValue ;
  58.        }else{
  59.         this.Qualification = '';
  60.        }
  61.  
  62.        if(this.picklistVal === 'Needs Analysis'){
  63.           this.NeedsAnalysis = this.StageValue ;
  64.        }else{
  65.         this.NeedsAnalysis = '';
  66.        }
  67.  
  68.        if(this.picklistVal === 'Value Proposition'){
  69.         this.ValueProposition = this.StageValue ;
  70.      }else{
  71.         this.ValueProposition = '';
  72.      }
  73.  
  74.      if(this.picklistVal === 'Id. Decision Makers'){
  75.         this.IdDecisionMakers = this.StageValue ;
  76.      }else{
  77.         this.IdDecisionMakers = '';
  78.      }
  79.  
  80.      if(this.picklistVal === 'Perception Analysis'){
  81.         this.PerceptionAnalysis = this.StageValue ;
  82.      }else{
  83.         this.PerceptionAnalysis = '';
  84.      } 
  85.  
  86.  
  87.     }
  88. }

Create Lightning Web Component Meta XML

Step 3:- Create Lightning Web Component Meta XML ➡ picklistValueLWC.js-meta.xml

SFDX:Lightning Web Component ➡ New >> picklistValueLWC.js-meta.xml

picklistValueLWC.js-meta.xml [LWC Meta Data XML]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets>
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.       </targets>
  10. </LightningComponentBundle>

fetch picklist values based on record type in salesforce lwc -- w3web.net

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is dynamic picklist in Salesforce?

Dynamic Picklists are multiple-choice questions that get their list of choices directly from Salesforce. Values are populated from Salesforce when the form loads.

What are Picklists in Salesforce?

Picklists are used in Salesforce to capture static data and define a list wherein users can select via accessing a drop-down menu.

How do I replace a picklist with global picklist?

For a global picklist value set: Go to the Global Value Set Detail page by clicking the picklist name. In the Values section, click Replace. For all other picklists: Click Replace next to the picklist name.

Related Topics | You May Also Like

 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration




Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment