function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dan Dodd 3Dan Dodd 3 

upload a file that belongs to a case

I am uploading case history to out new salesforce Helpdesk. 
We are receiving new cases via the Email-to-case method.

When a case is created by email-to-case an attachment is saved as a file connected to the case.

I am able to upload the case history via the API but I dont see how to pass a filename and get the file unloaded and attached.  
 
AnudeepAnudeep (Salesforce Developers) 
Hi Dan, 

You can try utilizing the name field in Attachment object: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

    Attachment attachment = new Attachment(); 
    attachment.Body = Blob.valueOf(encodedContentsString); 
    attachment.Name = String.valueOf('test.txt'); 
    attachment.ParentId = accountId; 
    insert attachment;

For EmailFileAttachment, there is filename field

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_attachment.htm

Anudeep

 
Dan Dodd 3Dan Dodd 3
Using your suggestion I am getting a valid response (201) to the API call but do not see the file in the case.
Is it possible I need to use a Fies API endpoint and not attachment?
Dan Dodd 3Dan Dodd 3
It looks like I need to use ContentVersion object. Anyone have an example of uploading a file via ContentVersion.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm?search_text=file