I had a similar challenge here trying to code a dynamic VFpage to display Case SLA Status, without hard-coding anything (there were lots of applications that needed it for different recordTypeIds).
I could achieve it by consuming an internal API from UI-API. Here it follows, in case it helps anyone else in the future:
First, reading a lot of documentation, I created this wrapper class, so I could deserialize the body of the api response:
public class PicklistWrapper {
public class CasePicklistValuesWrapper {
public Map<String, Integer> controllerValues;
public CasePicklistValue defaultValue;
public String url;
public List<CasePicklistValue> values;
}
public class CasePicklistValue {
public CaseStatusCasePicklistAttributes attributes;
public String label;
public Integer[] validFor;
public String value;
}
public class CaseStatusCasePicklistAttributes {
public Boolean closed;
public String CasepicklistAtrributesValueType;
}
}
Then, inside of a Apex class which I am using as Extension of the VFpage, I got a map like this:
public List<PicklistWrapper.CasePicklistValue> getCasePicklistValuesByRecordTypeId(Id idRT){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/services/data/v53.0/ui-api/object-info/Case/picklist-values/' + idRT + '/Status');
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
PicklistWrapper.CasePicklistValuesWrapper picklistValuesWrapper = (PicklistWrapper.CasePicklistValuesWrapper) JSON.deserialize(res.getBody(), PicklistWrapper.CasePicklistValuesWrapper.class);
return picklistValuesWrapper.values;
}
Then, my code enters in some other stuff. But basically you can iterate it with something like this (I didn't specifically test this little piece of code, I am just trying to create some example) :
List<PicklistWrapper.CasePicklistValue> picklistValueList = getCasePicklistValuesByRecordTypeId(returnedCase.RecordTypeId);
Map<Integer,String> correctSequenceToStatusMap = new Map<Integer,String>;
Integer sequence = 1;
for(PicklistWrapper.CasePicklistValue picklistValue : picklistValueList){
// label
System.debug(picklistValue.label);
// api value
System.debug(picklistValue.value);
// just some random map to exemplify
correctSequenceToStatusMap.put(sequence,picklistValue.label);
sequence++;
}
I hope this helps someone!