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
Paul 32Paul 32 

Trying to return values for 3 picklist values from custom object in apex class

Hi, I am trying to return the picklist values from 3 picklists from a custom object. So far i can return the values from 1 picklist which i use to populate a lightning:select field in my component, but can i get the other 2 picklists in the same call, or do i have to get them seperatly?
Best Answer chosen by Paul 32
sfdcMonkey.comsfdcMonkey.com
Hi Paul,
check following post :
http://sfdcmonkey.com/2016/12/05/how-to-fetch-picklist-value-from-sobject-and-set-in-uiinputselect/

for fetch 3 picklist values you just need to update in doInit funtion of above post like this :

doInit: function(component, event, helper) {
        helper.fetchPickListVal(component, 'firstFieldAPI__c', 'auraIdOne');
        helper.fetchPickListVal(component, 'secondFieldAPI__c', 'auraIdTwo');
        helper.fetchPickListVal(component, 'ThirdFieldAPI__c', 'auraIdThree');
 },

Regards
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you find a post helpful and it answers your question, please mark it as an "Best Answer"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
 

All Answers

RKSalesforceRKSalesforce
Hi Paul,

You can achieve  this thing in a single call by using Dynamic Apex. Please use below code to get Picklist Values in  a single call, You need to change Object Name and Field name in the code:
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;
}
Please mark as best answer if helped.

Regards,
Ramakant
 
Paul 32Paul 32
HI Ramakant,

Thanks for the response, but your example only returns the picklist values for the field specified, so in yor example it returns the values for Country__c. What i want to do is return the picklist values for 3 picklists which are Region__c, Status__c, Stage__c. 

Thanks,
Paul
RKSalesforceRKSalesforce
Hi Paul,

I thing you need seperate calls for 3 different picklist fields.

Regards,
Ramakant
sfdcMonkey.comsfdcMonkey.com
Hi Paul,
check following post :
http://sfdcmonkey.com/2016/12/05/how-to-fetch-picklist-value-from-sobject-and-set-in-uiinputselect/

for fetch 3 picklist values you just need to update in doInit funtion of above post like this :

doInit: function(component, event, helper) {
        helper.fetchPickListVal(component, 'firstFieldAPI__c', 'auraIdOne');
        helper.fetchPickListVal(component, 'secondFieldAPI__c', 'auraIdTwo');
        helper.fetchPickListVal(component, 'ThirdFieldAPI__c', 'auraIdThree');
 },

Regards
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you find a post helpful and it answers your question, please mark it as an "Best Answer"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
 
This was selected as the best answer
Paul 32Paul 32
Hey Piyush, that helped me modify my code and it now works - Thanks for the help!!