8

In a test class, I'm passing a value of a restricted picklist. Below is the value, and the screenshot of the restricted picklist LOVs:-

SVMXC__Quote_Line__c testQuoteLine = new SVMXC__Quote_Line__c();
testQuoteLine.ESMX_Maintenance_Window__c='SWE Reg – Regular Labour, Semi-Weekend (e.g. Saturday)';

enter image description here

Even though, as it can be seen, we are passing the correct value, we are getting the below error while running the test class:-

System.DmlException: Update failed. First exception on row 0 with id a34g0000000v3ceAAA; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Maintenance Window: bad value for restricted picklist field: SWE Reg – Regular Labour, Semi-Weekend (e.g. Saturday): [ESMX_Maintenance_Window__c]

N.B.: No record type or Field dependency issue faced here.

3 Answers 3

6

probably the value you want to enter isnt exposed to the record type.

  1. go to the object`s record type
  2. select the relevant one
  3. select the relevant "picklists Available for Editing" for edit
  4. add the values
1

I ran into this same issue and it turned out that I didn't have the correct field dependency set. If you're also using Field Dependencies, check to ensure the value in question is enabled for the correct controlling field values.

0

Since, picklist values have been stored as API Name (in the database), so you need to assign the API Name of the picklist item.

SVMXC__Quote_Line__c testQuoteLine = new SVMXC__Quote_Line__c();
testQuoteLine.ESMX_Maintenance_Window__c='SWE Reg';

In the UI, it will be displayed as value [SWE Reg – Regular Labour, Semi-Weekend (e.g. Saturday)]

6
  • Hi Santanu, Thank you for the response. However, even providing the API name, I'm encountering the same issue. Commented Aug 16, 2018 at 11:42
  • Is that script is getting run by a specific user? Do you have any recordtype? Commented Aug 16, 2018 at 11:49
  • As mentioned, there is no record type restriction. Also the script is not being run by any user. The FLS is set to the user which I'm logged in. Commented Aug 16, 2018 at 11:54
  • check that any space is there in the API Name, Also, suggest you to create a record from UI and check how it is storing as SVMXC__Quote_Line__c's record and replicate same data in test class Commented Aug 16, 2018 at 11:59
  • Have you specified default value on picklist field? Please check this link help.salesforce.com/…. Commented Aug 16, 2018 at 13:56

You must log in to answer this question.

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