2

When using Salesforce composite getting this error. How to resolve this?

Cannot deserialize instance of currency from VALUE_STRING value 1,9459.1650 or request may be missing a required field

Thanks in advance

2
  • I think that you need to remove the , from that string. This might be difficult to do, however, given that all the other commas are needed. You could chop the string up by looking for the JSON name - say you know it's called 'cost' ... find from this for eg {cost: 1,9459.1560, someothervalue: "something"} - look for 'cost' and replace the FIRST instance of a comma after that. Make sense? Mar 11 at 21:01
  • 2
    Hi, and welcome to SFSE! Please take a moment to read about How to Ask, and take the tour. In order for us to properly help you, we need more information. Please describe exactly what you're trying to do, and provide any relevant code. This will help us narrow down an appropriate solution for you.
    – sfdcfox
    Mar 11 at 21:09
2

I think that you need to remove the , from that string. This might be difficult to do, however, given that all the other commas are needed.

You could chop the string up by looking for the JSON name - say you know it's called 'cost' ... find from this for eg

{cost: 1,9459.1560, someothervalue: "something", more: "something else"}` 
  • look for 'cost' and replace the FIRST instance of a comma after that.

Or split on ,

You would get an array like this:

['cost: 1']
['9459.1560']
['someothervalue: "something"']
['more: "something else"']

From here you can scan through the array (backwards) and find any object with no : It clearly belongs to the previous name value pair.

eg:

String[] fixedJSONArray = new String[]{};
for(Integer i = badJSONArray.length -1, i > -1, i--){
  String nameVal = badJSONArray[i];
  if (nameVal.contains(':')){
    fixedJSONArray.push(nameVal);
  }
  else {
    fixedJSONArray.push(badJSONArray[i-1] + nameVal);
  }
}
String fixedJSON = '{' + String.join(fixedJSONArray,',') + '}';
5
  • How do you know it's JSON? What if it's CSV? Or something else? I'm just curious.
    – sfdcfox
    Mar 11 at 21:07
  • 1
    Hahah it's always JSON! Anyway, same principle applies. Mar 11 at 21:14
  • Oh and composite - that's a composite http - which is json Mar 11 at 21:15
  • Thanks it worked :-) Mar 11 at 21:28
  • Btw ... this could break if there are more commas etc in the number. For that you will need a fancier algorithm - maybe something recursive. Mar 11 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.