Skip to main content

#Json0 personne en discute

2 commentaires
0/9000

Below is the response from an external system. In Salesforce, I need to save the value of test1. Now JSON Parser it trying to destruct the test1 value also because it has escape character before the double quotes. When I try to replace the \" with \\", it is replacing all the quotes with \\" instead of replacing the test1 value. Is there any other alternative way to parse this JSON Response?

 

#Apex  #Json  #Integration #Salesforce Developer

 

String s = '{ "test1": " {\"test1\":[{\"firstId\":\"Id1\"}]}", "test2" : "test2" }';

//This line throws an error since parser is trying to destruct the test1 value also.

//Map<String, Object> deserializedString = (Map<String, Object>) JSON.deserializeUnTyped(s);

//There won't be any slash in the output.

System.debug('s value ++ '+ s);

//s value ++ { "test1": " {"test1":[{"firstId":"Id1"}]}", "test2" : "test2" }

//It will replace all the double quotes with slash and double quotes. I just need to add an extra slash to the test1 value.

System.debug('After Replacing++ '+ s.replace('\"','\\"'));

//After Replacing++ { \"test1\": \" {\"test1\":[{\"firstId\":\"Id1\"}]}\", \"test2\" : \"test2\" }

1 réponse
0/9000

Hi All, 

 

I'm trying to make a class that extracts the details from a record and format it to a JSON file but for some reason, it's getting cut off when I print it in System.debug thus getting an error of "Parameter is empty/incomplete".

 

Is there a limit in sending a JSON format file to a third party tool?

Limit to send JSON format in Apex

 

Thank you!

#Json #Apex 

4 réponses
  1. 11 août 2021, 05:02

    Hi Ann,

     

    Could you please Open Raw Log and check the debug logs in there? In dev console, you might not get the whole debug log, but in raw logs, you might get one.

     

    There is a panel at the bottom in the dev console itself. Right click on your log, and click on Open Raw Log.

     

    Hope this helps!

0/9000

Hi,

How can I merge JSON Data Node in array while using Dataraptor transform.

 

How can I merge JSON Data Node in array while using Dataraptor transform.

 I am trying to achieve the following JSON : 

{

    "Forecast": [

        {

            "Date": "2021-01-26",

            "Condition": "Heavy Snow",

            "HiLoTempF": "30.5/21.7",

            "HiLoTempC": "-0.8/-5.7"

        },

        {

            "Date": "2021-01-27",

            "Condition": "Light Snow",

            "HiLoTempF": "31.7/22.8",

            "HiLoTempC": "-0.2/-5.1"

        },

        {

            "HiLoTempF": "31.0/18.7",

            "Date": "2021-01-28",

            "Condition": "Flurries",

            "HiLoTempC": "-0.6/-7.8"

        },

        {

            "HiLoTempF": "25.3/18.1",

            "Date": "2021-01-29",

            "Condition": "Clear sky",

            "HiLoTempC": "-3.7/-7.7"

        },

        {

            "HiLoTempF": "24.2/19.7",

            "Date": "2021-01-30",

            "Condition": "Clear sky",

            "HiLoTempC": "-4.3/-6.8"

        }

    ],

    "Current": {

        "Condition": "Heavy Snow",

        "CityState": "Schenectady, New York",

        "TempF": 27.5,

        "TempC": -2.5

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/s03d.png",

    "ForecastIcon": "www.weatherbit.io/static/img/icons/s01d.png"

}

 

But I'm Getting Forecast Data in each separate node:

[

  {

    "Forecast": {

      "Date": "2021-08-02"

    },

    "ForecastIcon": "www.weatherbit.io/static/img/icons/r03d.png",

    "Current": {

      "TempF": 17.2,

      "CityState": "Roosevelt Island, NY",

      "Condition": "Clear sky"

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/c01n.png"

  },

  {

    "ForecastIcon": "www.weatherbit.io/static/img/icons/r02d.png",

    "Current": {

      "TempF": 17.2,

      "CityState": "Roosevelt Island, NY",

      "Condition": "Clear sky"

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/c01n.png"

  },

  {

    "ForecastIcon": "www.weatherbit.io/static/img/icons/r02d.png",

    "Current": {

      "TempF": 17.2,

      "CityState": "Roosevelt Island, NY",

      "Condition": "Clear sky"

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/c01n.png"

  },

  {

    "ForecastIcon": "www.weatherbit.io/static/img/icons/r01d.png",

    "Current": {

      "TempF": 17.2,

      "CityState": "Roosevelt Island, NY",

      "Condition": "Clear sky"

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/c01n.png"

  },

  {

    "ForecastIcon": "www.weatherbit.io/static/img/icons/c04d.png",

    "Current": {

      "TempF": 17.2,

      "CityState": "Roosevelt Island, NY",

      "Condition": "Clear sky"

    },

    "CurrentIcon": "www.weatherbit.io/static/img/icons/c01n.png"

  }

]

 

#Trailhead #Vlocity #Json

1 réponse
  1. 3 août 2021, 11:07

    Hello @Asheesh Sahu,

    You need to add 4 formulas like below :

     

    Hello ,You need to add 4 formulas like below : Now in the Transform section, Match Input and Output JSON Path like below: After successfully doing above things you will get the desired result in the f

     

    1627988397410.jpg

    Now in the Transform section, Match Input and Output JSON Path like below:

     

    1627988397398.jpg

     

    After successfully doing above things you will get the desired result in the format as you are expecting!

     

    1627988397430.jpg

     

    Hope it helps:)

    Let me know if you have nay doubts!! Please feel free to mark as best answer if that helps!!

    Thanks :D

0/9000
Meenu sweety (Anna University) a posé une question dans #Trailhead

I'm new to Apex . I have JSON data I need to convert to JSON Generator.

 

JSON data

 

#API  #Apex  #Json  #Salesforce  #REST API  #Trailhead

Contact app = [select Id, Name from Contact ];

{

"CustomerID": 0,

"CustomerType": 1,

"Name": "callum, john", (app.Name,app.LastName) like this i need in JSON Generator.

"BranchID": 1,

"CustomerAddress": [

{

"CustomerAddressID": 0,

"CustomerID": 0,

"Address": {

"Address1": "Test",

"TownCityID": 41037,

"CountyID": null,

"StateID": 41036,

"CountryID": 4,

"Country": "Australia"

},

"AddressTypeID": 1,

"DateMovedIn": "11/09/2019",

"IsPrimary": false

}

],

"Persons": [

{

"PersonID": 0,

"Title": 1,

"Gender": 0,

"ForenamePartOne": "callum",

"ForenamePartTwo": null,

"ForenamePartThree": null,

"Surname": "john",

"DateOfBirth": "11/09/1970",

"SocialSecurityNumber": "35",

"telephone1": "",

"telephone2": "",

"telephone3": "6598307315"

}

],

"CorrespondenceName": "callum, john",

"DateJoined": "11/09/2019"

}

6 réponses
  1. 20 juil. 2021, 17:40

    Hello @Meenu sweety,

    Actually in your code

    At start take a String and put value as app.FirstName +' ,' + app.LastName and use that for Name 

    gen.writeStringField('BranchID', '1');

    gen.writeStartObject(); // This line should not be present

    gen.writeFieldName('CustomerAddress');

    gen.writeObject(null); // Instead of this you should use gen.writeStartArray()

    and use gen.writeStartObject(); at the next line and end them accordingly also do same for "Persons"

0/9000

Hi - this is part of a JSON file where the productResults can be empty or it can contain one or more entries:

 

"quotation": {		"quotationId": 168862733,		"retrievalToken": "bTec+xrBlRBqq1liLqaq/Q==",		"quotationOutcome": "Scored",		"productResults": []	},

The data is deserialized, here is part of the data structure:

 

public class ProductResults {    public String productId;    public Integer likelihoodValue;    public String defactoId;    public ProductDetails productDetails;  }  public class Quotation {    public Integer quotationID;    public String retrievalToken;    public String quotationOutcome;    public String declineReason;    public List<ProductResults> productResults;  }

After it has been deserialized, in Apex I want to check to see if the productResults has any data, so I have tried the following, but even when it is empty as above this is still returning True:

 

 if(quotation != NULL && quotation.productResults != NULL){

Is the syntax correct?

 

#Apex  #Json

4 réponses
  1. 19 juil. 2021, 13:28

    I've not tried this through... but I would think since your productResults is being set to an empty list here in your JSON that you'd beed to use isEmpty() or size() instead of checking for null

    ... "productResults":[] ....

    So maybe more like this?  

     if(quotation != NULL && !quotation.productResults.isEmpty()){

    Also, you could use the null safe operator to cut your code down... I think this would work.

     if(!quotation?.productResults?.isEmpty()){
0/9000

Hi, 

A tough question, I tested it through dev console in 2 unrelated orgs and both of them gave the same strange result.

I run this code through anonymous window, which basically takes a JSON and through deserializeUntyped method, breaks it to pieces: 

string ex='{"Quote Line_Repeating":[{"Quote Line":{"Line ID":"1","Discount":"true","Discount Type":"Regular","Sell Multiplier":1,"Rep Net Multiplier":0.75,"Pricing":"true","Base List Price":866,"Base Currency":"USD","Quote List Price":866,"Quote Currency":"USD","Exchange Rate":1}}]}';Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(ex);List<Object> a = (List<Object>)m.get('Quote Line_Repeating');System.debug('ex: '+ex);System.debug('m: '+m);

 

The result that I got for ex variable:

USER_DEBUG [6]|DEBUG|ex: {"Quote Line_Repeating":[{"Quote Line":{"Line ID":"1","Discount":"true","Discount Type":"Regular","Sell Multiplier":1,"Rep Net Multiplier":0.75,"Pricing":"true","Base List Price":866,"Base Currency":"USD","Quote List Price":866,"Quote Currency":"USD","Exchange Rate":1}}]}

The results which I got for m variable:

USER_DEBUG [7]|DEBUG|USER_DEBUG [7]|DEBUG|m: {Quote Line_Repeating=({Quote Line={Base Currency=USD, Base List Price=866, Discount=true, Discount Type=Regular, Exchange Rate=1, Line ID=1, Pricing=true, Quote Currency=USD, Quote List Price=866, Rep Net Multiplier=0.75, ...}})}

If you compare carefully the 2 logs, you'll see that after going through JSON.deserializeUntyped method, the "Sell Multiplier":1 value just vanished from the view and the log shows 

only 3 dots. It's seems that the 'deserializeUntyped' sorted the attributes and omitted all attributes after the 10th attribute. In addition, I tweak the JSON by adding and removing attributes and always the result was the same, the first 10 alphabetical attributes appeared and the other were omitted.

I think that it's a bug, as I didn't find any documentation about this kind of SF limit, but maybe I'm missing something.

I'll be happy for assistance Thanks

Victor

1 réponse
  1. 3 juil. 2021, 20:35

    Hi Victor, 

     

    The "Sell Multiplier":1 is not getting vanished, it's still there. Those 3 dots at the end means that the line was too long to display, hence got truncated after a certain number of characters.

    This was mentioned in the release notes of Spring' 19 [ https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_forcecom_developer_console.htm ].

     

    To overcome this truncation limit, use the JSON.serialize method inside the System.debug method.

    Example Code:

    String ex = '{"Quote Line_Repeating":[{"Quote Line":{"Line ID":"1","Discount":"true","Discount Type":"Regular","Sell Multiplier":1,"Rep Net Multiplier":0.75,"Pricing":"true","Base List Price":866,"Base Currency":"USD","Quote List Price":866,"Quote Currency":"USD","Exchange Rate":1}}]}';

    Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(ex);

    List<Object> a = (List<Object>)m.get('Quote Line_Repeating');

    System.debug('ex: ' + ex);

    System.debug('m: ' + m);

    System.debug('m(no-trucation): ' + JSON.serialize(m)); // prints the full object with all the keys visible

    Resulting Logs:

    USER_DEBUG|[4]|DEBUG|ex: {"Quote Line_Repeating":[{"Quote Line":{"Line ID":"1","Discount":"true","Discount Type":"Regular","Sell Multiplier":1,"Rep Net Multiplier":0.75,"Pricing":"true","Base List Price":866,"Base Currency":"USD","Quote List Price":866,"Quote Currency":"USD","Exchange Rate":1}}]}

    USER_DEBUG|[5]|DEBUG|m: {Quote Line_Repeating=({Quote Line={Base Currency=USD, Base List Price=866, Discount=true, Discount Type=Regular, Exchange Rate=1, Line ID=1, Pricing=true, Quote Currency=USD, Quote List Price=866, Rep Net Multiplier=0.75, ...}})}

    USER_DEBUG|[6]|DEBUG|m(no-truncation): {"Quote Line_Repeating":[{"Quote Line":{"Exchange Rate":1,"Quote Currency":"USD","Quote List Price":866,"Base Currency":"USD","Base List Price":866,"Pricing":"true","Rep Net Multiplier":0.75,"Sell Multiplier":1,"Discount Type":"Regular","Discount":"true","Line ID":"1"}}]}

    Output of Line no. 6 prints the complete object with all the keys visible including the key "Sell Multiplier":1.

     

    Reordering of keys:

    It is observed in the output above, that in Line no. 5, the keys are sorted in an alphabetical order. While on Line no. 6, the same keys are now sorted in reverse of their original order(i.e. Line no. 4).

    Hence the ordering of keys is not guarantied to be same. Also the JSON or Maps are considered to be an un-ordered collectionof key-value pair. So we must never rely upon the ordering of their keys.

     

    If some use case demands the ordering to remain constant, then one can make use of a List in Apex. Because they are an ordered collection of elements.

     

    Do you need those keys to be in a particular order? If yes, then kindly mention your use case, because I can't think of any as of now.

     

    Regards

    Manish

0/9000

Hi All - this seems so silly, but I have a Dell Boomi process that uploads a dataset into TCRM.  It works fine in full copy sandbox, but I'm getting metadata errors in production.  How can I view the JSON for the dataset (not the XMD) from each org to compare them?  I must be blind, but I'm googled out.  Thanks in advance!!

3 commentaires
0/9000

Hi All!  Having an issue with the JSON filter on the EA Dashboard component in Partner Community. The dataset for sales history data contains the AccountID, so attempting to use "!CurrentUser.accountId" to retrieve the logged in users account ID and display the information but getting no records.  If I insert a valid accountID in place of the "!CurrentUser.accountId", results are fine.  (I have also tried "$CurrentUser.accountId"). I'm sure it's something simple, if anyone has time to reply I'd appreciate it!! THANKS....full filter shown here:

 {"datasets":{

"AllInvoicesByDealer":[

{"fields":["Account.Id"],

"filter":{

"operator":"in",

"values": ["!CurrentUser.accountId"]

}

}

]

}

}

18 commentaires
0/9000

Hey All, 

 

Trying to do some fairly basic binding work but I'm running into issues. 

 

I'm trying to do a binding that has opportunity value ranges. Basically, "Low" == "500k-1m" and "High" == "5m-10m" and then clicking either option will return Opps in those values on a chart, for example.

 

Curiously, I am able to achieve this in the SAQL code, however I want to do it in the advanced editor and it doesn't work. I get no errors, but also nothing happens to the chart when the toggle options are selected. 

 

Here is the code I am using to try and achieve this:

 

 "filters": [

            [

                "TotalPrice",

                [

                    "{{cell(myStatic_1.selection, 0, \"Number2\").asRange(\"TotalPrice\")}}"

                ],

                "=="

            ]

        ],

 

It would be great for anyone to help spot where i am going wrong and help me achieve this bind in the JSON advanced editor! Thank you!

1 commentaire
0/9000