Last active
October 11, 2023 18:00
-
-
Save viviramji/044986ec0e9f9b21df134769ad1f11e3 to your computer and use it in GitHub Desktop.
Apex Class for getting dynamic picklist values from object setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
getDataPicklist: function(cmp) { | |
cmp.set("v.showSpinner", true); | |
var action = cmp.get("c.picklist_values"); | |
action.setParams({ | |
object_name: "Opportunity", | |
fieldNames: cmp.get("StageName") // ["StageName"] | |
}); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
console.log(response.getReturnValue()); | |
cmp.set("v.StageOptions", response.getReturnValue()[0]); | |
} else { | |
console.log("error"); | |
cmp.set("v.showSpinner", false); | |
} | |
}); | |
$A.enqueueAction(action); | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import picklist_values from "@salesforce/apex/Utility.picklist_values"; | |
updateActionPlans({ | |
object_name: "Opportunity", | |
fieldNames: ["StageName"] | |
}) | |
.then((result) => { | |
if (result) { | |
console.log(result); | |
} | |
this.error = undefined; | |
}) | |
.catch((error) => { | |
console.log(error); | |
this.error = error; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class Utility { | |
/* | |
* picklist_values method | |
* @Descrition | |
* Method used to get a list of picklist values from a given object and fields | |
* @params | |
* object_name - String | |
* fieldNames - List<String> | |
* @return | |
* List<List<String>> which each position corresponds to the picklist values of the given field | |
*/ | |
@AuraEnabled | |
public static List<List<String>> picklist_values(String object_name, List<String> fieldNames) { | |
List<List<string>> t = new List<List<String>>(); | |
List<String> types = new List<String>(); | |
List<String> typesValues = new List<String>(); | |
//List<String> field_names = new List<String>{'Billing_Method__c','Billing_Day_Of_Month__c','Exp_Date_Month__c'}; | |
types.add(object_name); | |
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types); | |
for(Schema.DescribeSobjectResult res : results) { | |
for(String field : fieldNames){ | |
List<String> values = new List<String>(); | |
//system.debug(field); | |
for (Schema.PicklistEntry entry : res.fields.getMap().get(field).getDescribe().getPicklistValues()) { | |
if (entry.isActive()) { | |
values.add(entry.getValue()); | |
} | |
} | |
//system.debug(values); | |
t.add(values); | |
} | |
} | |
return t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment