4

I'm getting the above error when trying to bring a few Apex classes over to Prod. I recently changed some values in our custom object Status picklist field. The one erroring here was Completed and I changed it to Training Complete. It seems not to recognize it. I've read that creating a controlling picklist can fix this error, but we don't want there to be a controlling picklist on this object. Any other ideas?

Full Error

System.DmlException: Update failed. First exception on row 0 with id a0V4000000VkpypEAB; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: Training Complete: [Status__c] Stack Trace: Class.ImplementationTriggerHandlerTest.test_method_one: line 19, column 1

@isTest
private class ImplementationTriggerHandlerTest {

    @isTest static void test_method_one() {
        Account acc = TestDataGenerator.getAccount();
        Insert acc;

        Implementation__c imp = TestDataGenerator.getImplementationAndInsert(acc);

        imp.Implementation_Status__c = 'Implementation Complete';
        Update imp;

        List<Training__c> trainingList = new List<Training__c>();
        for(Training__c t : [SELECT Id FROM Training__c]){
            t.Status__c = 'Training Complete';
            trainingList.add(t);
        }

        Update trainingList;

        delete imp;
    }
}
4
  • Can you confirm if 'Training Complete' is actually a configured value for the Status__c field?
    – Adrian Larson
    Aug 22 '17 at 15:58
  • Yep it's a value.
    – Heather
    Aug 22 '17 at 16:27
  • 1
    Check if there are extra spaces in your Training Complete value in the picklist field (in the middle or at the end). Also if you have record types on the custom object, make sure the value is available for the record type you're using in the test. Aug 22 '17 at 20:15
  • I also face this issue even checking that the field is available on the RecordType and has no spaces. My workaround is to inactivate the 'Restrict picklist value' checkbox. But I still trying to find out how to solve it.
    – compski
    Jan 13 at 6:29
3

please include the picklist values in the record type and deploy the field with record type as well. Also check if that picklist value is there in that field.

If not you can remove the restrict picklist values checkbox on that field -> deploy it, then manually check it

2
  • But then the code won't read the value once it's in Prod because it doesn't read it now. Right?
    – Heather
    Aug 22 '17 at 16:45
  • 1
    Yes, Heather in case if it is restricted picklist then this error is possible only on two scenarios: 1) when the value itself is not included in the picklist or 2) when that picklist is not included in the record type. If you take care of these two, we will never get this error Aug 23 '17 at 3:56
0

Check if you are changing the Training__c RecordType Value to something else in the apex classes/triggers/ Process Builder/Flow/Workflow Rules

OR

Ensure all the record types of that certain picklist value has 'Training Complete' value available in Training__c object.

It is very likely that there is automatic process changing the record type during an Update of Training__c record to a recordtype that doesn't have that picklist value. I just had this happen to me and it is super frustrating.

0

Make sure you look for extra spaces or slightly different characters in the test values you are setting compared to the actual API picklist values. I spent about 30 minutes wonder why my apex test was failing. Turns out the developer who added the picklist value included an extra space in the api name that wasn't in the value I was testing with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.