33 votes
Accepted

How to retrieve the file content for a ContentDocument object?

The Content tables are considerably more complex than Attachments. The file content is held in the ContentVersion object; one ContentDocument has one or many versions, as well as an arbitrary number ...
  • 88.2k
14 votes
Accepted

how to upload files using Apex code

ContentDocument object does not allow insert DML operation in Salesforce, so we can upload it through the ContentVersion object, without ContentDocumentId. After DML on ContentVersion a new version ...
13 votes

Is it possible to get a sharing link (to non SFDC users) from 'files'/'content' via apex?

The idea thread mentioned by @crmprogdev is now realized. As of winter 15 there is now programmatic access to content deliveries. ContentDistribution cd = new ContentDistribution(); cd.name = 'test'...
  • 9,607
13 votes

Files as email attachment from Apex

If you have the ContentDocument Id you can fetch the ContentVersion file as this: // If you only want the ContentVersion ID's Map<Id, ContentVersion> contentVersions = new Map<Id, ...
  • 1,872
9 votes
Accepted

Uploading 100,000 binary files as attachments to Case record - best approach

I would suggest you to go with data loader using SOAP API, which is by default (not Bulk API). Why? You do not need to write any code to use Data loader It is tested solution, so no bugs With ...
  • 8,990
8 votes
Accepted

Save attachment with Remote Objects

Based on the error message you get when you attempt to retrieve the body of an attachment: Visualforce Remoting Exception: No serializer found for class common.udd.object.EncryptableFfxBlobField$...
8 votes
Accepted

How to query a file uploaded as an attachment in lightning experience?

Files are stored in the ContentDocument Object .You will have to run a SOQL against contentDocument link first and look for all Content Version DocumentLink with EntityId as the ParentId of the ...
8 votes
Accepted

Issue while uploading file greater than 5MB

The actual limit is going to be closer to 4,500,000 bytes before encoding. Note that it has never been possible to send more than 12,000,000 bytes of data in a single transaction, and even then, only ...
  • 445k
8 votes
Accepted

Does sending a file to an external server fall under the heap size limit considerations?

Various Apex limits will get in the way of trying to push the data from Salesforce. Instead, one approach is to signal to the third-party application that the file is ready to be moved via a HTTPS ...
  • 131k
7 votes
Accepted

Salesforce isn't handling Base64 Encoded attachments uploaded via Rest API

Based on my research, I have concluded that at the time of this writing (using REST API v32), Salesforce does not decode uploaded base64 encoded data for Attachments. This is a bit confusing, since ...
  • 1,039
7 votes

Download Invoice PDF's On List View without saving to Notes and Attachment as a zip file

Kudos to @SFDCGOD for suggesting this. I was so intrigued by his suggestion, I gave it a try. First, I created resources for each of the Javascript files (FileSaver.js and jszip.js) and then created ...
7 votes

how to upload files using Apex code

I found a way to insert ContentVersion and attach it to Record in one SOQL. <apex:page controller="ContentController"> <apex:form> <apex:inputFile value="{!file}" /> ...
  • 533
7 votes
Accepted

Cloning Attachment

If you are cloning the attachment then only just pass the attachment id and parentId to the controller. In the controller cloneAttachment() method, retrieve the child attachment information from SOQL....
6 votes

Standard "Send an Email" with Attachments

Drawloop will allow you to select which attachments you want to send, but the catch is you have to send a PDF merge file as part of the email. But if that is what you are doing anyway then Drawloop ...
  • 1,160
6 votes
Accepted

Visualforce page to render attachment.body

You have two challenges ahead of you. One is easy, one is impossible. Let's start with the easy one. Extra Whitespace? Any whitespace that doesn't separate attributes will end up in the output ...
  • 445k
6 votes
Accepted

dataURL to blob

You need to specify the file extension when giving name to the attachment. a.Name = 'attachment.png'; Or alternatively set the ContentType attribute - Attachment Object Update: Your string is ...
6 votes
Accepted

Download Invoice PDF's On List View without saving to Notes and Attachment as a zip file

You can do following to achieve this: Add following javascript in your page FileSaver.min.js Blob.js jszip.min.js Pass All Id's to controller and just get there data by getContetnAsPdf one by ...
  • 1,040
6 votes
Accepted

SOQL Query getting Notes and Attachments from Custom Object

You have to use the correct Relationship Name (Notes). Also you don't need to check for parentId condition again in the inner query.. select Id, Request_Title__c, (SELECT Id, Name FROM Attachments), ...
6 votes
Accepted

Cannot deserialize instance of base64 from VALUE_STRING value

I just tested serializing and deserializing an attachment in Salesforce, and JSON.serialize gave me something like this: [{"attributes": {"type":"Attachment", "url":"/services/data/v37.0/sobjects/...
  • 445k
6 votes

Export Salesforce report data into PDF format in APEX

Firstly, you might want to vote for the idea Ability to Print Reports to PDF. Maybe with an additional comment that you want it export to PDF in the same way that it can to CSV. You can use Blob....
6 votes
Accepted

How to edit the "created by" field for case attachments?

Take a look at this help article: Considerations before having Create Audit Fields enabled: Salesforce has the ability to set system fields through the API. When you are migrating data from an ...
  • 144k
5 votes

How Get Parent Field in Attachment?

There is a feature you can use in your own orgs, via a pilot feature, called TYPEOF, that allows you to get a parent field for a concrete type. That query looks like this: SELECT Id, Name, TYPEOF ...
  • 445k
5 votes
Accepted

Enabling Notes and Attachments after custom object creation

This checkbox simply saves you the trouble of having to drag the Notes and Attachments related list onto the page layout. Here I forget to do this on creating my new object. Oh no! If I go to the ...
  • 19.2k
5 votes

Comparing a text with a attachment body

You just need to convert the Body data (Blob Type) to text (String type). Attachment record; // defined in your context somewhere Blob body = record.Body; // Blob data type String content = body....
  • 144k
5 votes

Migrate attachments to Salesforce Files

FYI Douglas Ayers has a package for automating this via Apex: https://douglascayers.com/2015/10/10/salesforce-convert-attachments-to-chatter-files/
5 votes
Accepted

Remove pictures as attachments inside an email

This was an idea which has been delivered in Winter 15 - specifically focusing on filtering attachments. I'm not sure if you are referring to filtering out attachments or simply removing them all ...
5 votes
Accepted

Creating a Map that has a List of Attachments as the Value

The code could look like this: Map<Id, List<Attachment>> emailMap = new Map<Id, List<Attachment>>(); for (Id id : validEmailIds) emailMap.put(id, new List<Attachment>());...
  • 131k
5 votes

How to query a file uploaded as an attachment in lightning experience?

In lightning when you upload attachments, it save as salesforce files. for querying salesforce files you need to understand three object: ContentVersion ContentDocumentLink ContentDocument for each ...
  • 13.4k
5 votes
Accepted

Uploading an attachment with Request

As it turns out, just using the regular formData object with multiple keys was the way to go. const options = { url: 'https://instance.salesforce.com/services/data/v38.0/sobjects/Attachment', ...
  • 71
5 votes
Accepted

Save base64 data as Attachment

Did you set the contentType as application/pdf? I tried this following code and it is working for me. String jsonStr = '<Base64 String>'; Attachment attach = new Attachment(); attach....
  • 13.6k

Only top scored, non community-wiki answers of a minimum length are eligible