function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tyler young 35tyler young 35 

"Cannot deserialize instance of Address from VALUE_STRING value" using C# API


I'm using the Salesforce.Force NuGet package to upsert records, and if I don't include the Address property on the Lead, it works just fine. When I include Address, it gives the following error (in JSON):

[{"message":"Cannot deserialize instance of Address from VALUE_STRING value IROQUOIS at [line:1, column:21]","errorCode":"JSON_PARSER_ERROR"}]

The relevant JSON sent to the server is:

{"Address":
    {
        "City":"IROQUOIS",
        "Country":"Canada",
        "CountryCode":"CAN",
        "PostalCode":"K0E 1K0",
        "State":"ONTARIO",
        "StateCode":"ON",
        "Street":"SENSITIVE_DATA_HERE"
    },
"Company":"SENSITIVE_DATA_HERE",
"Description":"SENSITIVE_DATA_HERE",
"Email":"SENSITIVE_DATA_HERE"....}


Any ideas on why it's having trouble deserializing the address?
 
Best Answer chosen by tyler young 35
Daniel BallingerDaniel Ballinger
Oddly, the capitalization of the JSON appears to impact how it is deserialized. If I send in the following JSON:
 
{"Address": {
        "City": "Nelson",
        "Country": "New Zealand",
        "CountryCode": null,
        "PostalCode": "7011",
        "State": "Nelson",
        "StateCode": null,
        "Street": "7 Forests Rd\r\nStoke"
    },
 "Company":"TestLeadCompany2",
"Description":"SENSITIVE_DATA_HERE",
"Email":"daniel.ballinger@example.com",
 "LastName": "Ballinger"}

I get the response:
[
    {
        "message": "Cannot deserialize instance of Address from VALUE_STRING value Nelson at [line:2, column:18]",
        "errorCode": "JSON_PARSER_ERROR"
    }
]
 
 
If the casing of the address members is converted to lower case, the response changes:
{"Address": {
        "city": "Nelson",
        "country": "New Zealand",
        "countryCode": null,
        "postalCode": "7011",
        "state": "Nelson",
        "stateCode": null,
        "street": "7 Forests Rd\r\nStoke"
    },
 "Company":"TestLeadCompany2",
"Description":"SENSITIVE_DATA_HERE",
"Email":"daniel.ballinger@example.com",
 "LastName": "Ballinger"}
[
    {
        "message": "Unable to create/update fields: Address. Please check the security settings of this field and verify that it is read/write for your profile or permission set.",
        "errorCode": "INVALID_FIELD_FOR_INSERT_UPDATE",
        "fields": [
            "Address"
        ]
    }
]
Instead you need to send in the Address data using the direct fields on the Lead.
{
  "City": "Nelson",
  "Country": "New Zealand",
  "PostalCode": "7011",
  "State": "Nelson",
  "Street": "7 Forests Rd\r\nStoke",
    
  "Company":"TestLeadCompany2",
  "Description":"SENSITIVE_DATA_HERE",
  "Email":"daniel.ballinger@example.com",
  "LastName": "Ballinger"
}


Gives:

{
    "id": "00Qo000000Hd2IxEAJ",
    "success": true,
    "errors": []
}

Does the Salesforce Toolkit (https://github.com/developerforce/Force.com-Toolkit-for-NET) provide directly properties that you can set on the Lead for City, Country, State, etc..?