You need to sign in to do that
Don't have an account?
Apex JSON.deserializeUntyped
Hi,
I'm using JSON.deserializeUntyped method, 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
It's seems that the 'deserializeUntyped' sorted the attributes and omitted all attributes after the 10th attribute.
In addition, I tweaked 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
Try the below code to get the Sell Multiplier from JSON:
Thanks,
Maharajan.C
All Answers
Please find the below document where you can find the reason why salesforce truncating the large strings with dots.
https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_forcecom_developer_console.htm
You can find the more expainations from below links:
https://salesforce.stackexchange.com/questions/116502/console-log-truncates-my-debug
https://salesforce.stackexchange.com/questions/253381/system-debug-messages-get-trimmed/253774#253774
Use the below ways to display the entire string.
Thanks,
Maharajan.C
Maharajan, maybe it's my fault and I didn't explain my problem well enough.
It's not only that dev console is trimming the string because it's too long and I can find the full log through Setup->Debug logs
The string is being actually trancated, for real (!) and the 11th attribute is not available for further logic.
if you execute this code, you would expect to get for the last line the value of '1', but instead you're getting nothing
Try the below code to get the Sell Multiplier from JSON:
Thanks,
Maharajan.C