You need to sign in to do that
Don't have an account?
Øyvind Borgersen 10
Help - Test class for picklist entries and labels
Hi,
I've written a code to get picklistvalues instead of api names and pass that value back. Can someone assist in a test class for the following code:
public without sharing class OneConsent {
//Method to be used in flow to pass Id to class -- Return string name
@InvocableMethod(label='Get Contact Citizenship name' description='Return the citizenship label')
public static List<String> getContactId (List<ID> ids) {
List<String> ContactId = new List<String>();
List<String> CitizenshipLabel = new List<String>();
// Use the describe information to generate a mapping from api name to label
List<Schema.PicklistEntry> PicklistEntries = Contact.hed__Citizenship__c.getDescribe().getPicklistValues();
map<String,String> ApiToLabel = new map<String,String>();
for (Schema.PicklistEntry pe : PicklistEntries){
ApiToLabel.put(pe.getValue(),pe.getLabel());
}
// List contact values to get current citizenship value
List<Contact> ContactValue = [SELECT hed__Citizenship__c FROM Contact WHERE Id in :ids];
// Loop contact value and assign picklist api name to picklist value
for(contact con: contactvalue) {
system.debug('Label'+ ApiToLabel.get(con.hed__Citizenship__c));
String str = string.valueOf(ApiToLabel.get(con.hed__Citizenship__c));
CitizenshipLabel.add(str);
}
return CitizenshipLabel;
}
}
I've written a code to get picklistvalues instead of api names and pass that value back. Can someone assist in a test class for the following code:
public without sharing class OneConsent {
//Method to be used in flow to pass Id to class -- Return string name
@InvocableMethod(label='Get Contact Citizenship name' description='Return the citizenship label')
public static List<String> getContactId (List<ID> ids) {
List<String> ContactId = new List<String>();
List<String> CitizenshipLabel = new List<String>();
// Use the describe information to generate a mapping from api name to label
List<Schema.PicklistEntry> PicklistEntries = Contact.hed__Citizenship__c.getDescribe().getPicklistValues();
map<String,String> ApiToLabel = new map<String,String>();
for (Schema.PicklistEntry pe : PicklistEntries){
ApiToLabel.put(pe.getValue(),pe.getLabel());
}
// List contact values to get current citizenship value
List<Contact> ContactValue = [SELECT hed__Citizenship__c FROM Contact WHERE Id in :ids];
// Loop contact value and assign picklist api name to picklist value
for(contact con: contactvalue) {
system.debug('Label'+ ApiToLabel.get(con.hed__Citizenship__c));
String str = string.valueOf(ApiToLabel.get(con.hed__Citizenship__c));
CitizenshipLabel.add(str);
}
return CitizenshipLabel;
}
}
Controller
Test Class
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you