+ Start a Discussion
Priya AakankshaPriya Aakanksha 

how to create attachments as files using apex in salesforce

i wants to attach pdf as file not as attachments while sending mail it should save in notes and attachments.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Priya,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.




I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Priya AakankshaPriya Aakanksha
// this code is attachment of pdf=====

public void saveAttachment(){
  String encodedContentsString = System.currentPageReference().getParameters().get('fileContents');
  Id accountId = System.currentPageReference().getParameters().get('accountId');
  Attachment attachment = new Attachment();
  attachment.Body = Blob.valueOf(encodedContentsString);
  attachment.Name = String.valueOf('test.txt');
  attachment.ParentId = accountId; 
  insert attachment;
If this is my code thn how to attach file as attachment