New answers tagged

1

It's not clear from the code how you are generating the JSON dynamically. Here is a sample code that might help. OrderAction public class OrderAction { public String type; public Action Action; public List<TriggerDate> triggerDates = new List<TriggerDate>(); // CONSTRUCTOR public OrderAction(String type) { ...


2

You can use an inline initializer: public class Messages { public List<Referral> Referral = new List<Referral>(); } Note that while deserializing a JSON string, if the property is missing or null, it will still be a null value.


4

You deserialize the JSON as you normally would, using either a strongly-typed Apex class with JSON.deserialize() or the untyped JSON.deserializeUntyped(), and then access this parameter as a String. Once you've got that value, call the unescapeHtml4() method, which replaces these Unicode entities with their actual character equivalents. All strings are ...


0

Things must have changed signficantly in the past few years, because it's quite simple now from what I can see as of Winter '20. It's a 1 line task to deserialize. In this example, I'm deserializing an external object to use in a Unit Test Mock. Part1 -- Serialize to a String. User__x testExtUser = [select Id, ExternalId, Name__c, FederationIdentifier__c,...


0

I got the solution from the link which I have posted in my question. I generated a class from Json2Apex and perform all the activity in same class. Below is my code - public class gettingDistance { @AuraEnabled public static String fetchUser(){ User oUser = [select Id, Name, Location__c FROM User Where id =: userInfo.getUserId()]; ...


2

You are trying to serialize a single object json to List<SObject>. Convert your JSON back to its original form which is not List.Try below code. Hope this helps. BRD_Recalculate_Response> BRD_Recalculate_Response = (BRD_Recalculate_Response)JSON.deserialize(responseString, BRD_Recalculate_Response.class);


2

This payload is not JSON and is not parseable without ugly and fragile workarounds. This is because it does not escape its field delimiter. Field values contain literal single quotes, meaning that any parser cannot distinguish between the end of a field value and the field's content. Replacing single quotes with double quotes will not work. This still won't ...


0

If you put your JSON into the JSON2Apex https://json2apex.herokuapp.com/ and generate the class you can add this class into you Org. Than you can call it like: JSON2APEX a = JSON2Apex.parse('yourJSONString'); System.debug(a.rows[0].elements[0].distance.value); This will give you the distance. If you look at the auto generated class you will see that the ...


0

The formatting with the JSON packet being transmitted to me seems to be the problem. The parameter device_config switches from being a string, device_config : "", to an array of strings, device_config : [...], whenever it isn't sent with the [] which is confusing Salesforce. Thank you all for your help


1

Found my answer. I passed the field as a null instead of a 0 length string and that corrected it.


2

Create a wrapper class for your object, such as @Samir suggested, but also serialise/deserialise as a list. List<SerializeObject> wrapperList = new List<SerializeObject>(); wrapperList.add(yourData); String jsonString = JSON.serialize(wrapperList); // [{"sicCode":"foo", "postCode":"bar", ...}] The square brackets you're looking for mean that ...


1

Create a corresponding class having all the attributes from json like below Public class serializeObject{ public string sicCode; public string postCode; public string isGeneratorFacility; public string externalID; ....... ....... } Then serialize your json like this List<serializeObject> objserialize = (list<...


0

Actually this 'is' possible. Attributes are rendered in reverse order, so you can just rename them in reverse alphabetical order: global class ResultDto { String zParlorCode; // 1st String yDepartmentCode; // 2nd String xEmployeeNumber; // 3rd String wName; // 4th } Of course explaining why your attributes are named like ...


2

Actually, the problem is that your source code isn't encoded properly. You need to escape the backslashes: String jsonStr='{"key":"value \\"subvalue\\""}'; System.debug(json.deserializeuntyped(jsonstr)); Note that in the actual JSON, there would only be a single backslash. Apex requires backslashes to be escaped in source code.


Top 50 recent answers are included