Am getting case subject "?utf-8?b?QW5vbWFseSBkZXRIY3Rpb24g4oCTIERFIFNIQVc?=" In this format from third party system. So am converting into string as below:

  1. String s= case.subject;
  2. String s1 = s.substring(10);
  3. String s2= s1.removeEnd('?=');
  4. Blob b= EncodingUtil.base64Decode(s2);
  5. String finalText = b.toString();
  6. Case.subject = finalText;

Test class:

Static testMethod void subjectDecoding(){
     Start test.startTest();
     Case c = new case();
     C.status = 'New';
     C.origin = 'Email';
     C.subject= '?utf-8?b? 
    Insert c;

This is giving desired string output into case subject through(before insert in trigger) trigger handler class. But when am writing test class and trying to insert case in that format am getting error as cannot insert and blob is not valid utf-8 format in the line 4/5 in the above code.

Please someone help in resolving the test class error

  • Can you include your test class in the question so the community can help you resolve the issue?
    – Mark Pond
    Commented Jan 9, 2023 at 5:54
  • Added the test class. Please check but couldn't indent it
    – Sweetie
    Commented Jan 9, 2023 at 6:12

1 Answer 1


You are doing a simple mistake just decrease the substring to 9 from 10. As it is missing the Q.

I tried to reproduce it and got the following output -

Anomaly detHction – DE SHAW

  • Thanks a lot, i was struggling with that issue..it worked great..
    – Sweetie
    Commented Jan 9, 2023 at 6:48
  • can you mark it as the best answer? Commented Jan 9, 2023 at 6:56
  • Sure will do, thanks
    – Sweetie
    Commented Jan 9, 2023 at 7:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .