From salesforce I Need to expose a webservice to accept pdf/txt files from Mule and once I receive I need to store in Salesforce as an Attachment. However, from Postman while trying to hit as below I am getting the below error. So, the question is

  1. Is Mule has to convert the details in blob to me ?
  2. Is there anyway I can receive file in Salesforce directly from 3rp party system/Mule ?

Pls suggest.enter image description here

once I receive the content I can store in salesforce like below.

newAttachment.Name =AttachmentName;
newAttachment.Body=[Actual content which is in file];
newAttachment.ContentType ='Something.txt or .pdf';
newAttachment.ParentId =ca.Id;
insert newAttachment;

You could construct a payload for use with a custom Apex class, the data would have to look like:

{ "request": { "Origin": "Web", "CaseNumber": "12345", "FileBody": "<base64-encoded-data>", ... } }

But this would be inefficient for large files, and you'd have to do manual encoding/decoding. Instead, consider using the Blob resources that are already built in to Salesorce:

POST /services/data/v48.0/sobjects/Attachment HTTP/1.1
Host: my-domain.my.salesforce.com
Authorization: Bearer <token>
Content-Type: multipart/form-data; boundary="unique-boundary"
Content-Length: <calculated-length>

Content-Disposition: form-data; name="entity_attachment"
Content-Type: application/json

{ "ParentId": "<caseId>", "ContentType": "application/pdf", "Name": "filename" }

Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="Lic docs.pdf"



Check the documentation for all of the rules regarding this syntax.

| improve this answer | |

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.