32 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 ...
user avatar
  • 86k
17 votes

How to create csv files in controller method from list

Rob's link is interesting and worth considering, though it looks like you have to pull the report data by making HTTPS requests which apart from code involves setting up Remote Site Settings. ...
user avatar
  • 129k
14 votes
Accepted

How to convert an Image SRC URL to Base64 using apex?

public class ImageUri { public static String getDataUriFromUri(String url) { HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); Http ...
user avatar
  • 430k
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'...
user avatar
  • 9,436
13 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 ...
user avatar
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, ...
user avatar
  • 1,862
12 votes
Accepted

How can I tell if a custom object supports notes and attachments?

This is possible, but in a rather roundabout way. There's no way to tell from a Schema.SObjectType or Schema.SObjectDescribeResult, but there is a slightly obscure method on Schema.DescribeFieldResult ...
user avatar
  • 22.1k
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 ...
user avatar
  • 8,979
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$...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 430k
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 ...
user avatar
  • 129k
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 ...
user avatar
  • 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 ...
user avatar
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}" /> ...
user avatar
  • 523
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....
user avatar
6 votes
Accepted

How to "deep clone including Attachments" without hitting the heap space governor limit?

Here is the solution that I was discussing in the comments. It's very similar in concept to your's except it tries to reduce the number of DML and SOQL statements by grouping the Attachments into ...
user avatar
  • 13.2k
6 votes
Accepted

renderAs PDF shows blank first page

I ended up using the following on the apex:image styleClass: position: absolute; top: 0; and it did the trick.
user avatar
  • 2,700
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 ...
user avatar
  • 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 ...
user avatar
  • 430k
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 ...
user avatar
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 ...
user avatar
  • 1,018
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), ...
user avatar
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/...
user avatar
  • 430k
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....
user avatar
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 ...
user avatar
  • 142k
5 votes
Accepted

Return a list of attachments for a custom object

You can add a property to the controller that returns the collection of attachments using the "lazy load" pattern like this: public Attachment[] attachments { get { if (attachments == ...
user avatar
  • 129k
5 votes
Accepted

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

According to this post, the answer to your question about using content packs would be "no". On the IdeaExchange you'll find a submission titled Allow Content Deliveries to be programmatically ...
user avatar
  • 40.3k
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 ...
user avatar
  • 430k
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 ...
user avatar
  • 19.1k

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