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 ...
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.
...
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 ...
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'...
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 ...
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, ...
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 ...
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
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 ...
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 ...
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 ...
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}" />
...
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
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 ...
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.
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 ...
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 ...
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 ...
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/...
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 ...
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 == ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
attachment × 692apex × 212
visualforce × 139
email × 68
trigger × 57
files × 55
pdf × 48
soql × 35
rest-api × 34
notes × 27
contentdocument × 23
data-loader × 22
lightning × 20
case × 20
custom-object × 19
upload × 18
blob × 18
contentversion × 16
lightning-aura-components × 15
javascript × 13
community × 13
csv × 13
images × 13
api × 12
permissions × 12