[SalesForce] Deployment failure: bad value for restricted picklist field

I am facing a weird issue during production deployment.

I have created a picklist field (which is not exist in Production) Lead_Assignment_Status__c which is by-default restricted and values are New and Assigned. This picklist is not mandatory field.

Lead Assignment Status

In the testSetup method, created lead records as follows and updated Lead_Assignment_Status__c = 'Assigned':

Lead objLead = new Lead();
        objLead.RecordTypeId = 'xxxx';
        objLead.Company = 'Test';
        objLead.FirstName = 'f1';
        objLead.LastName = 'l1';
        objLead.Lead_Stage__c = 'New';
        objLead.Status ='New';
        objLead.LeadSource ='External Referral';
        objLead.Email ='test@gmail.com';
        objLead.IsConverted = false;
        objLead.OwnerId = UserId; 
insert objLead;

//updates Lead with Assigned Status
       objLead.Lead_Assignment_Status__c = 'Assigned'; 
       update objLead; 

During deployment this code snippet is failing with this error at this line update objLead;:

System.DmlException: Update failed. First exception on row 0 with id 00Q16000018n8DREAY; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field: Assigned: [Lead_Assignment_Status__c]

When I run this test class at our development environment it is running without any errors.

My question is why this is failing during deployment.

Best Answer

If your Lead object employs Record Types, the most likely culprit for this error is that you have not included relevant Record Type(s) in your deployment.

The error bad value for restricted picklist field is encountered when a picklist option isn't available for that field under the specific Record Type of an inserted Lead record (perhaps the default Record Type, in your case).

Including the relevant Record Type in your deployment will bring over the picklist options for all picklist fields as they've been configured for that Record Type in your sandbox, and in most cases will resolve the error without having to create the field manually in Production beforehand.

Related Topic