3

I am trying to create a custom visualforce page that is aware of the Case Status Values that are related to a specific Case Support Process.

I am able to get all Status Picklist Values from a Describe method:

Schema.DescribeFieldResult fieldResult = Case.Status.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

Or I can get there Case Status values from the CaseStatus sObject:

SELECT Id, MasterLabel, ApiName, SortOrder, IsDefault, IsClosed FROM CaseStatus

I can get information about the Support process from the BusinessProcess sObject:

SELECT Id, Name, Description, TableEnumOrId, IsActive FROM BusinessProcess

However I can find no way to link the Case Status Values programatically to a defined Business Process. This can be seen in the UI below. I need to identify Programatically the Selected Case Statuses for a specified Support Process.

enter image description here

2
  • There doesn’t seem to be a direct way to do so, but you can using metadata api. The api returns picklist values associated to the process.
    – Jayant Das
    Commented May 17, 2018 at 12:53
  • This is a longstanding problem: getting recordtypes associated with picklist values from schema describes doesn't get you what you want. It's a real shortcoming of the platform. There are convoluted methods using the MDAPI that can help you, but no great solutions. Great summary posted here: salesforce.stackexchange.com/questions/103837/….
    – crmprogdev
    Commented May 17, 2018 at 13:36

2 Answers 2

0

Ideally if its just a pure case status field that you want, an apex:inputField should be sufficient and respect Support Processes given you have setup record types on your controller object.

However I think youre doing something more funky like me. I had the use case of creating a selectList for case values that filtered only 'Closed' statuses that still respects the case support process.

Just a clear gritty way of getting this done using VF and javascript/jquery. Key note would be that inputfield does respect support processes and record types, so my solution is basically rendering a display-none version of said field. Traversing it via jQuery and saving it into a hash array and then using that hash array to toggle the visibility of the core field to be displayed

<apex:inputField id="StatusReference" style="display:none; width: 500px;" value="{!myCase.Status}" />


<apex:selectList id="StatusActual" size="1" style="width: 500px;" value="{!myCase.Status}">

<script>
    j$ = jQuery.noConflict();

    var statusValues = new Array();

    j$('select[id*=StatusReference] option').each(function() {
        console.log(this.text + ' ' + this.value);
        statusValues[this.text] = this.value;
    });

    j$('select[id*=StatusActual] option').each(function() {
         if(statusValues[this.value] == undefined){ this.style.display = 'none';}
    });
</script>

I wish there was a cleaner way but no way I'm messing around with Metadata API for a single drop down :D and salesforce do make it so hard at times and you do just deal with the cards youre dealt. but as a famous quote would say 'These violent delights have violent ends'

0

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .