object-sync-for-salesforce icon indicating copy to clipboard operation
object-sync-for-salesforce copied to clipboard

Restricted picklists return a bad value error

Open jonathanstegall opened this issue 7 years ago • 7 comments

This is the same issue we have in minnpost/salesforce-stripe#14 - even if you combine the desired values with semicolons, as Salesforce expects, a restricted picklist field will return an error.

jonathanstegall avatar Dec 19 '17 20:12 jonathanstegall

Salesforce documents this error at https://help.salesforce.com/articleView?id=000250168&language=en_US&type=1. It is not particularly helpful though.

jonathanstegall avatar Dec 19 '17 20:12 jonathanstegall

This is an interesting post as well: https://salesforce.stackexchange.com/questions/9322/what-does-a-restricted-picklist-mean

In addition to @LaceySnr 's thorough documentation, this bad value for restricted picklist field: error will occur if you are setting a picklist value to X and...

The Sobject has recordtypes The recordtype you are using for that Sobject does not include X as an allowed value for the picklist.

jonathanstegall avatar Dec 19 '17 20:12 jonathanstegall

And just for kicks, I posted a question about this to StackExchange. https://salesforce.stackexchange.com/questions/202368/api-error-bad-value-for-restricted-picklist-field

jonathanstegall avatar Dec 19 '17 21:12 jonathanstegall

This is a Salesforce configuration error. Here's what I had to do (in Salesforce):

  1. Go to Setup
  2. Customize -> Opportunities (I am testing with an opportunity picklist at the moment; presumably we’ll need to do this for all record types with restricted picklists)
  3. Click Record Types under Opportunities
  4. Click the name of the desired record type (for me it was Default, but I’ll also need to apply it to some other opportunity types). Clicking Edit didn’t work for this; only clicking the name. So the URL ends up being like this: /setup/ui/recordtypefields.jsp?id=012F00000013Gkq&type=Opportunity&setupid=OpportunityRecords
  5. Scroll down to the desired picklist and click Edit
  6. Move the values from Available Values to Selected Values (I didn’t pick a default because we don’t have a default for this picklist) and Save

After I did these things, I was able to send values from WordPress to the restricted picklist without errors.

I'm going to look into the API results and see if anything changes on this field, to see if we could possibly notify users about this issue instead of just returning an error.

jonathanstegall avatar Dec 20 '17 15:12 jonathanstegall

The API does not seem to change the data it sends when values are moved from Available Values to Selected Values. I think there's nothing we can do about this, but it does seem like it'd be worth putting it into the documentation somewhere, since Salesforce never seems to document exactly what they mean by record type.

jonathanstegall avatar Dec 20 '17 15:12 jonathanstegall

I ran a test by disallowing one of the values, and allowing four other values, on the picklist. Trying to submit all 5 returns a 400 error as before, while submitting the 4 allowed ones is fine.

However the data that Salesforce returns about the field is the same for all five fields:

[picklistValues] => Array
(
    [0] => Array
        (
            [active] => 1
            [defaultValue] => 
            [label] => Bierschbach
            [validFor] => 
            [value] => Bierschbach
        )

    [1] => Array
        (
            [active] => 1
            [defaultValue] => 
            [label] => Black
            [validFor] => 
            [value] => Black
        )

    [2] => Array
        (
            [active] => 1
            [defaultValue] => 
            [label] => Espeland
            [validFor] => 
            [value] => Espeland
        )

    [3] => Array
        (
            [active] => 1
            [defaultValue] => 
            [label] => Hirsi
            [validFor] => 
            [value] => Hirsi
        )

    [4] => Array
        (
            [active] => 1
            [defaultValue] => 
            [label] => Meador
            [validFor] => 
            [value] => Meador
        )

)

jonathanstegall avatar Dec 20 '17 16:12 jonathanstegall

What I meant by the above comment, which is not clear now that I read it two weeks later, is that the API response from Salesforce is not different for restricted picklists; that is, the API response does not know whether the field has the proper Selected Values.

I think because of this, we should do one or both of these things:

  1. Put documentation in the plugin that describes this issue and the solution as it is in Salesforce.
  2. Put a message into the plugin itself when a user tries to map a restricted picklist. Tell them (one time; dismissable) that they should make sure the picklist is set up properly in Salesforce.

jonathanstegall avatar Jan 02 '18 14:01 jonathanstegall