Added explanation: Since the Case.picklistField is constantly modified by other Org user (non-developer), so I want to avoid data dependency as much as I could.
I have a case trigger method using 'label from a Case.picklistField' to map the action, and now I come across a problem:
The test method I've written CANNOT set label to the Case.picklistField, only can set value to the Case.picklistField.
My goal is to add a new value/label set to the picklist field other then the now exist value/label set, which is only be used in test method.
Trigger method goes like this:
//Get AutoClose__c setting from CustomObj
Map<String, Boolean> AutoCloseFuction_M = new Map<String, Boolean>();
for(CustomObj objCS : [Select Function_Labelname__c, AutoClose__c From CustomObj where AutoClose__c = true ])
AutoCloseFuction_M.put(objCS.Function_Labelname__c, objCS.AutoClose__c);
//Get (value, label) from Case.PicklistField__c
Map<String,String> MapValueLabel = new Map<String,String>();
Schema.DescribeFieldResult fieldResult = Case.PicklistField__c.getDescribe();
List<Schema.PicklistEntry> values = fieldResult.getPicklistValues();
for( Schema.PicklistEntry v : values) {
MapValueLabel.put(v.getValue(),v.getLabel());
}
//Main logic Start
for(Case C: triggerNewL)
{
if( String.isNotBlank(C.PicklistField__c) )
{
if(
( AutoCloseFuction_M.containsKey( MapValueLabel.get(C.PicklistField__c) ) )&&
( C.Disable_AutoClose__c == false )
)
{
C.Status = 'Close';
}
}
}
//Main logic End