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
RonGongRonGong 

Cannot deserialize instance of complexvalue from VALUE_STRING value

Hey SF Community,

I'm trying to update a workflowalert through the tooling api and when I try to generate the json I am getting the following error with the recipient "type" field set to "user" and the "senderType" field set to "CurrentUser".  I've noticed that these are both enumeration fields, do they have to be generated differently?

Here is the error I can receiving:
[{"message":"Cannot deserialize instance of complexvalue from VALUE_STRING value user at [line:7, column:37]","errorCode":"JSON_PARSER_ERROR"}]

Here is the code I used to generate the json:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('Metadata');
gen.writeStartObject();
gen.writeStringField('description', 'testing');
gen.writeStringField('template', 'EmailFolder/CustomerPortalChangePwdEmail');
gen.writeStringField('senderType', 'CurrentUser');
gen.writeFieldName('recipients');
gen.writeStartArray();
gen.writeStartObject();
gen.writeNullField('field');
gen.writeStringField('recipient', 'ron@rondev.com');
gen.writeStringField('type', 'user');
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndObject();

Any help is appreciated.  Thanks!
James LoghryJames Loghry
Not sure what your exact issue is, but have you taken a look at either https://github.com/afawcett/apex-toolingapi or https://github.com/afawcett/apex-toolingapi/tree/apex-toolingapi-rest?  To integrate with the RESTful version of the tooling API, what we did was investigate the request / response for the tooling API and then use the JSON 2 Apex heroku app (http://json2apex.herokuapp.com/) to generate the Apex classes necessary.  This way you don't need to write your own JSON Generator class and will likely not run into the issue you're having.