You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having issues with the ForceClient.ExecuteRestApiAsync() methods.
I have written a custom RestResource in my salesforce instance similar to this:
@RestResource(urlMapping='/myResource/*')
global class MyResource {
@HttpPost
global static MyResponse post() {
try {
// Some operation that results in an exception
}
catch (Exception e) {
RestContext.response.statusCode = 400;
MyResponse r = new MyResponse();
r.myCustomMessage = 'Something happened: ' + e.getMessage();
}
}
}
after evaluating the async task I get the exception:
System.Exception : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Salesforce.Common.Models.Json.ErrorResponses' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'myCustomMessage ', line 1, position 19. ---->
--JsonSerializationException
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Salesforce.Common.JsonHttpClient.ParseForceException(String responseMessage)
at Salesforce.Common.JsonHttpClient.<HttpPostAsync>d__9`1.MoveNext()
In the method Salesforce.Common.JsonHttpClient.ParseForceException(String responseMessage) I have found that the code attempts to deserialize any response that doesn't have a successful HTTP Response Code to an ErrorResponses model, which is a collection of ErrorResponse classes.
I understand that this is the default error model for DML requests through the Salesforce API, but it doesn't allow for handling error response implementations for RestResources. Are we able to resolve this?
The text was updated successfully, but these errors were encountered:
Hey @wadewegner, I have submitted a pull request (link above), however the test automation in the CI/CD pipeline has old configuration and is failing tests. Are you able to let me know how to proceed.
I am having issues with the ForceClient.ExecuteRestApiAsync() methods.
I have written a custom RestResource in my salesforce instance similar to this:
Then using the Force Client as below
SalesforceConnector.ForceClient.ExecuteRestApiAsync<MyResponse>("myResource");
after evaluating the async task I get the exception:
In the method
Salesforce.Common.JsonHttpClient.ParseForceException(String responseMessage)
I have found that the code attempts to deserialize any response that doesn't have a successful HTTP Response Code to anErrorResponses
model, which is a collection ofErrorResponse
classes.I understand that this is the default error model for DML requests through the Salesforce API, but it doesn't allow for handling error response implementations for RestResources. Are we able to resolve this?
The text was updated successfully, but these errors were encountered: