When upserting the fields of Attachment such as Name, upsert works while upserting body like:

SObject upsertDoc1 = new SObject("Attachment");
            upsertDoc1.setField("Name", "dummyattach_gloria.txt");
            upsertDoc1.setField("ID", "00P1a000000FrAAACA0");
            upsertDoc1.setField("Body", "aHR0cDovL3N0bGFiLmFkb2JlLmNvbS93aWtpL2ltYWdlcy9kL2QzL1Rlc3QucGRm");

The upsert fails with the error:

The Upsert failed because: Body: value not of required type: aHR0cDovL3N0bGFiLmFkb2JlLmNvbS93aWtpL2ltYWdlcy9kL2QzL1Rlc3QucGRm

This is a Base64 field. How do I deal with this kind of update? Additionally, should I also be updating the BodyLength or will it be handled automatically?


  • If you also set the "ContentType" to "text/plain" does it still fail? I notice that the base64 decodes to the text "stlab.adobe.com/wiki/images/d/d3/Test.pdf".
    – Keith C
    May 28, 2015 at 22:03
  • Yes, still fails. I don't think this is an issue with the other fields.
    – dmachop
    May 28, 2015 at 22:06

1 Answer 1


you should pass a byte [] as the value to setField, not the base64 encoded value, the SOAP client will automatically encode it for you.

You must log in to answer this question.

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