Questions tagged [serialization]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
23 views

How to loop trough subquery and fill fields in array Json object

I have created a custom object to create a json string. I kan loop trough the list to fill in the first level/parent fields. How do I loop trough the subquery and fill the arrays in the json object. ...
0
votes
2answers
34 views

Serialize and deserialize a list of Sobject for Future method

I am trying to pass a list Account records to a future method. Since future can only take primitives, I am planning to serialize and deserialize the Sobject. I tried below: List<Account> acList;...
4
votes
2answers
107 views

How to adding dynamic rows/fields to wrapper class?

I have written the following WrapperClass, consisting different object records/rows/fields as members. How can I dynamically update this wrapper class object. In below code i have used only two fields ...
1
vote
1answer
46 views

Convert object as string to json

I have an object which is converted to string in a text field. How can I convert this to a JSON string. String of object: Profile:[UID=, crmId=0000o00002XXXXxXXX, email=top@top.com, firstname=null, ...
4
votes
1answer
195 views

Cannot use deserialized JSON for populating map - why?

I have deserialized some JSON into lists of objects: Map<String, Object> Results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); List<Object> ...
1
vote
0answers
120 views

JSON time fields

We have a problem with deserialize and serialize salesforce time fields Since Json and salesforce time fields both consist of "colon" we need to replace with a special character before deserialize ...
0
votes
0answers
29 views

Why salesforce remote action response wrapped in extra keys?

I am calling simple remote action, and returning a response object, in my object I don't have any properties like "s" and "v" but they still appear in my raw json response. I am not sure whether ...
0
votes
2answers
58 views

Is it possible to create a generic Map swapper?

I have a method: public Map<Object, Object> swap(Map<Object, Object> valueByKeyMap) { Map<Object, Object> keyByValueMap = new Map<Object, Object>(); for (Object key : ...
0
votes
1answer
51 views

Would it be better to use Serialized/Deserialize or Lists for generalized Set creation?

As a Salesforce developer, I find I frequently need to extract Sets from List<SObject>, so I'm looking to create a generalized way of creating Sets. The problem is, Salesforce thinks Set<...
0
votes
1answer
55 views

Best Structure for Multiple Sub Classes

I have a JSON string of which I always know 2/3 of the structure will be the same, but the last third will be different based on the source. I want to try to build structured types for this in apex so ...
0
votes
0answers
45 views

How to store a collection type (set, map, list) on a object?

I have a visual-force page which displays an Apex form with some dynamic number of input text fields that I would like to save on the Opportunity object. Is the easiest way to serialize them as JSON ...
4
votes
1answer
163 views

JSON serialization across managed packages

We're having an ecosystem of managed packages where one is dependend on another and sometimes there is a need that one package (e.g. extension package) need to serialize some objects from another ...
2
votes
2answers
245 views

How to control the property name of a serialised object using Apex

BACKGROUND I need to generate the below JSON data: JSON { "Type": "ACCPAYCREDIT", "Status": "AUTHORISED", "Contact": { "ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc" }, "Date": ...
2
votes
1answer
3k views

How to return Json string

I have a Get Method which returns an invoice based on id. When I test this with Workbench I would like to have the following response: { "customerId": "1", "addressId": "2018AA123", "invoiceId": "...
0
votes
1answer
96 views

Convert Multile Objects to a single json

I have a list of map and list objects. These objects needs to be sent as json content in an http request. The objects are Map<String,String> leftFileParameters = new Map<String,String>()...
1
vote
1answer
554 views

JSON.serialize Url object throwing System.JSONException

I'm getting the following JSONException when JSON serializing a Map of generic Objects which contains a Url object deeply nested within. System.JSONException: Type unsupported in JSON: common.apex....
1
vote
1answer
171 views

How to build and serialize

Keith C's answer builds the following "config" output: config: {option1: {isActive: true, isRequired: true}, option2: {isActive: true, isRequired: true} } by looping ...
-2
votes
2answers
19k views

Create JSON using apex

I do not have any idea about this, but I am trying to create JSON using Apex class. I think it can be done using serialize method. But I need a simple example so that I can understand the procedure. ...
0
votes
1answer
242 views

Error desearlizing JSON of type BatchInfo - Bulk API

I am trying to get the status,# record processed etc details by hitting the bulk API endpoint - /services/async/39.0/job/75037000003BXtw/batch In response I got the below JSON structure: {"batchInfo"...
0
votes
0answers
161 views

Apex: Making key lowercased in json serialized version of object

The usual way to serialize hierarchy of objects in json looks like this in Apex: String json = JSON.serialize(rootNode); My requirement is to send this json to our external system. But they want to ...
1
vote
0answers
309 views

json.serialize returning null

List<ClassName.CustomerDetails> CustomerDetailsList = new List<ClassName.CustomerDetails> (); ClassName.CustomerDetails custDetails = new ClassName.CustomerDetails(); ...
1
vote
2answers
714 views

Making “Null” as “” in JSON payload

I am trying to push a JSON input payload, but some fields might be blank. The receiving system has a problem with it. They want either the blank fields to not be sent all together or replace "Null" ...
3
votes
2answers
3k views

System.TypeException: Invalid conversion from runtime type Map<String,ANY> to Map<String,String>

I have the following Program which gives me the following error: System.TypeException: Invalid conversion from runtime type Map<String,ANY> to Map<String,String> The program which I ...
7
votes
1answer
2k views

deserializeStrict method: bug?

The documentation about the deserializeStrict method in JSON class is (emphasis added): All attributes in the JSON string must be present in the specified type. If the JSON content contains ...
2
votes
1answer
767 views

I want to pass an HttpRequest object to a Class that implements the Queueable interface

This is similar to this question, but I'm wondering about the object I'm sending into the Queueable Class. Here's the Queuable Class (not much more than debug statements at this point) public class ...
3
votes
2answers
289 views

Deserialise json in apex

How to deserialize the below json ? I want to retrieve messages only in list of string . { "posts": { "data": [ { "message": "Hello. My name is sdfd. How can I help you?", "created_time": "...
1
vote
1answer
419 views

getChildElement element failing null pointer exception

I have the below XML response which I am trying to parse through XML parser. But I am facing error i.e null pointer exception in debug log for the line: if(objXMLNode.getChildElement('...
10
votes
1answer
476 views

Most Efficient Method to Convert Set Type?

I have a twist on this question. What is the relative performance of each of the following methods? Via Peter Knolle: public static Set<String> deserializeToStrings(Set<Id> input) { ...
2
votes
1answer
291 views

Serialize JSON attribute that is a reserved keyword in Apex

To use the Javascript tree library DynaTree on my Visualforce page I create JSON data in its controller List<DynaTreeNode> rootNodes = nodesByParentId.get(null).values(); dynaTreeJson = JSON....
2
votes
3answers
1k views

Convert SObjects containing child/parent records into a map

How can the following list of records be serialized/deserialized into a map or collection? Account[] accs = [select id, name, custom_parent__r.name, (select lastname, firstname from Contacts) from ...
11
votes
2answers
20k views

Deserialize JSON to SObject

Following code is giving me common.apex.runtime.impl.ExecutionException String jsonText = '{"Data": {"attributes": {"type": "Contact"},"Id": "0036100000JUXKkAAP","Description": "","LastName": "...
6
votes
1answer
611 views

Why does JSON.Serialize return null when passed a value of type System.Address?

Background I'm working on a project where I'm communicating with an external billing system to create a new Account in our external billing system when a new Account is created in Salesforce. Being ...
1
vote
2answers
2k views

What is the best way to create XML from a custom object and use that xml to create records of another custom object?

I have two custom objects . How to transfer the records from one custom object to another using xml ?
0
votes
0answers
413 views

Unexpected parameter encountered during deserialization

I am trying to write a REST service which will send SF objects between Orgs. Right now, as a test, I am sending data to the same Org that it is coming from. I wrote a GET request which worked so I ...
2
votes
2answers
3k views

What XML support salesforce provides in apex

(i) Is it possible to directly serialize/deserialize sObject record to xml in apex code? (ii) Is it possible to serialize/deserialize apex object to/from xml?
3
votes
1answer
1k views

Dynamically serialize or deserialize properties in apex

I want to have dynamic properties in my JSON structure, something like this - { "payload": { "one": { "x": 1 }, "two": { "x": ...
6
votes
2answers
324 views

Is there any logic to how SFDC serializes classes to JSON?

I'm working on documentation for a number of APEX REST API endpoints which returned user-defined types. I'm struggling to write the documentation since the order of how things are serialized into JSON ...
1
vote
1answer
994 views

salesforce .net toolkit relationship query serialization

I created strongly type classes to use when using the toolkit to query salesforce public class SFAccount { public string Id { get; set; } public string Name { get; set; } public ...
5
votes
0answers
295 views

JSON.serialize alternative which support more objects like HttpRequest or Schema Describes

Often I need a easy and robust way to convert huge nested data structures into an string. Mostly for dumps, logs and debug. JSON.serializePretty() comes close but does not support all Object types ...
5
votes
2answers
3k views

Apex Rest JSON serialization Error: Invalid type for Http* method: …Map.Object

Background I'm developing some generics apex web service (Rest). The response should be an standardised json schema like this: { "res": true, "message": "Records Upserted Ok", "data" : {ANYTHING}...
5
votes
1answer
526 views

How to JSON.serialize an opportunities line items?

How can I JSON.serialize an opportunities line items? I need to create a single json file, that holds an oppty as well as it's line items. If I just JSON.serialize(opportunity), I get all the Oppty'...
21
votes
2answers
2k views

What are the different capabilities between the @RemoteAction serializer and JSON.serialize?

I've been working quite a bit with @RemoteAction methods and have noticed there seem to be a few inconsistencies between what's allowed in the apex JSON.(de)serialize methods and what the automatic ...
3
votes
1answer
3k views

Unable to deserialize json data accessed from salesforce object in asp.net

I need to access data records from salesforce object. I got the json response.The json document is given below, { "totalSize":2, "done":true, "records": [{"attributes": { "type":"...