I'm trying to find a way to update an attachment's body from a custom visual force page I've created. I have the attachment ID but when I try to call a PATCH
web request on the URL: http://appid.salesforce.com/services/data/v38.0/sobjects/Attachment/{attachmentId}
I get the following http error:
BAD REQUEST: Unable to create/update fields: ParentId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.
How can I update an existing attachment's body? I don't want to create a new attachment or anything like that.
The I execute the request is the following:
var objectUrl = http://appid.salesforce.com/services/data/v38.0/sobjects/Attachment/0660L000000WLlH;
xhr.open("PATCH", objectUrl);
xhr.setRequestHeader("Authorization", "OAuth " + SFsessionId);
xhr.setRequestHeader("X-PrettyPrint", "1");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.send(attachmentBody);
where attachmentBody
is:
var attachment = JSON.stringify({
name: documentName,
ContentType: "application/pdf",
body: pdfAsBase64,
ParentId: parentid,
Description: "pdf data"
});
EDIT:
The problem is the ParentId: parentid
. During updating it must not be included. Only once during creation.
https://yourInstance.salesforce.com
. try again while changinghttp
->https
and instance in the URL apart from what Alexander has mentioned.