New answers tagged

0

Aura/LWC supports direct serialization/deserialization of objects. Just use: @AuraEnabled public static MockResponse updateRecords(sObject[] records) { As for the client side, make sure there's an attributes property: [ { "attributes": { "type": "Contact" }, "FirstName": "John", ... }, ... ] Coincidentally, ...


0

In policyresponse you might be getting an empty string '' or a whitespace string ' '. You can do a anonymous apex and check with this code: JsonParser objJsonParser = (JsonParser) JSON.deserialize('', JsonParser.class); OR JsonParser objJsonParser = (JsonParser) JSON.deserialize(' ', JsonParser.class); Do proper String null, empty and Blank check before ...


0

So I would not recommend JSON parsing via AMPScript. I would utilize Serve-Side JavaScript (SSJS) or Guide Template Language (GTL) to do this. I almost exclusively recommend SSJS as I feel it gives you more options and capabilities, but it also has a bit heavier overhead to learn and use. Here is an example in SSJS: <script runat=server> Platform.Load(&...


1

Do examine the incoming JSON carefully. A single \ in front of an embedded " is the correct escaping in JSON. But to represent a literal \ in an Apex String, as in your code sample, you need a second escaping backslash. So, for example, this parses and the assert passes: String s = '{"a": "b\\"d"}'; Map<String, Object> m = ...


1

Here is what I think you are looking for: Map<String, Wrapper> prs = new Map<String, Wrapper>(); for (Object obj: allData) { Wrapper pr = prs.get(obj.Primary_Stakeholder__c); if (pr == null) { // Need a new object to represent the primary stakeholder pr = new Wrapper(); pr.key = obj.Id; pr.label = obj....


0

I think this example can help you. Parse a JSON String and Deserialize It into Objects This example uses a hardcoded JSON string, which is the same JSON string returned by the callout in the previous example. In this example, the entire string is parsed into Invoice objects using the readValueAs method. This code also uses the skipChildren method to skip ...


1

At the end, I came up with this solution: First, I remodelled the Wrapper class like this: public class Wrapper{ List<cA> recordsA; public class cA{ cB recordB; public class cB{ String _some_id; // <--- Here I'm getting the error } } } After that, I used JSON.deserializeUntyped to control ...


1

The Naming Convention for Variables/Attributes in Apex can't have any special character in the beginning. So, As identigral mentioned in the comment, You can either use JSONParser to get the values from the JSON body or an easier approach would be to simply replace the attribute from the JSON itself. Wrapper.cA dataResponse = (Wrapper.cA)JSON.deserialize(...


0

This answer is not meant to solve your issue, instead is meant to point that @sfdcfox gave you the exact answer to the question you asked. To prove it I ran a test here with this result


2

The = [i] is what's causing the problem, at least in part. However, this isn't very JavaScript-y; you simply use Array.prototype.map instead: object = object.map((value,index) => ({ ...value, ABC: index })); Here we use Array.prototype.map, which uses a callback function to determine what the new value should be based on the old value. (params) => ({.....


1

I would use Object.assign. see code const data = [{ a: 1, b: 2 }, { b: 4, c: 5 }]; const data2 = {ASD:10}; for (let i = 0; i < data.length; i++) { data[i] = Object.assign(data[i], data2); } console.log(data); See link. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign


2

I did the following and was able to get the shortUrl: var result = HTTP.Post(url, contentType, Stringify(payload), headerNames, headerValues); var resultStringified = Stringify(result) var obj = Platform.Function.ParseJSON(resultStringified); var objResp = Platform.Function.ParseJSON(obj.Response[0]); var shortUrl = objResp.shortUrl; Write(...


0

You written almost correct method. In your filter method, Cat parameter itself is testobject, so you don't need to do again Cat.testobject.Cat. Please check your Cat case in JSON. As of now its different(Cat A vs cat B). Make sure its of same cases. I tested with similar JSON - { "tryi": "ytugfjfhg", "testobject": [{ ...


Top 50 recent answers are included