0

I am getting the below error while running a batch class in salesforce which was updating the records of Asset. In the batch class I was updating few date fields.

execution of AfterUpdate System.JSONException: Unexpected character ('Ôªø' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

I am not sure why it's coming. Any thoughts ?

1
  • Can you elaborate on the functionality performed by the batch class? Can you setup debug logs to see what value is being passed, which is not meeting the expected input type. As the error suggests, the input should be a valid value (number, String, array, object, 'true', 'false' or 'null')
    – Swetha
    Aug 4 '20 at 10:20
1

Unicode character 0xfeff is a BOM (Byte Order Mark), and not part of any valid Unicode character page. Some systems may emit this value at the beginning of a file, but Apex doesn't recognize those bytes, causing the problem you see here. As a quick fix, remove those values from the beginning, if present:

String fixedString = EncodingUtil.convertFromHex(
  EncodingUtil.convertToHex(Blob.valueOf(sourceString))
    .removeStart('feff').removeStart('fffe')
).toString();

Note: if you're starting with a Blob already, don't use Blob.valueOf.

Alternatively, fix the source to exclude these two bytes, if possible (some text editors include the ability to emit or omit the BOM, depending on a setting or flag).

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.