Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
34 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 ...
David Reed's user avatar
  • 93.1k
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 ...
Jai Chaturvedi's 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, ...
Simonp's user avatar
  • 1,892
9 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}" /> ...
Kritik's user avatar
  • 266
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 ...
AtulRajguru9's user avatar
  • 9,120
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 ...
Mohith Shrivastava's 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 ...
sfdcfox's user avatar
  • 494k
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 ...
Keith C's user avatar
  • 136k
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....
Santanu Boral's user avatar
7 votes
Accepted

Difference between Attachments and ContentDocument

Attachments are being deprecated in favor of using Files. The ContentDocument object represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files. https://...
Mark Pond's user avatar
  • 23k
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/...
sfdcfox's user avatar
  • 494k
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....
Daniel Ballinger's 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 ...
Adrian Larson's user avatar
  • 150k
6 votes
Accepted

Upload and store 50 MB file from LWC

There's a maximum payload for LWC components (~4MB last I checked), and there's also a maximum String size, clamped at Limits.getLimitHeapSize() (so, 6MB for an AuraEnabled method); you'd get away ...
sfdcfox's user avatar
  • 494k
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/
benedwards44's user avatar
5 votes
Accepted

Migrate attachments to Salesforce Files

Migration - from Attachment to Salesforce Files After a lot of RnD, came up with the following: Export Attachments data using data loader. Export Attachment files, using data export wizard or File ...
Mahmood's user avatar
  • 5,944
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 ...
sfdcfox's user avatar
  • 494k
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....
Adrian Larson's user avatar
  • 150k
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 ...
Gaurav Kheterpal's user avatar
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>());...
Keith C's user avatar
  • 136k
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 ...
sanket kumar's user avatar
  • 15.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', ...
John's user avatar
  • 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....
Saroj Bera's user avatar
  • 14.7k
5 votes
Accepted

Public Imageurl

You can insert a ContentDelivery, and then get the URL of that. If you have a set of ContentDistributions (and can fill in some blanks that I've removed becomes I'm relying on some of our internal ...
Aidan's user avatar
  • 13.7k
5 votes
Accepted

Setting the Attachment Owner as another User

Attachment object doesn't have separate OWD settings, and if an user has access to the Parent object then that user can access to Attachment record. Secondly, when the attachment is created then ...
Santanu Boral's user avatar
5 votes
Accepted

Finding records of an object type that has any attachment

You can filter your query on the field Parent.Type, whose value is an sObject name: SELECT ParentId, Id FROM Attachment WHERE Parent.Type = 'Account' That will get you back record-by-record level ...
David Reed's user avatar
  • 93.1k
5 votes
Accepted

Upload Attachments to Files Related list using Apex

Like the option says it attaches files only when its uploaded from related list(Only from the standard related list UI). From apex you're supposed to insert a contentDocument, which is a salesforce ...
Hemavantha Rajesh Varma Mudunu's user avatar
4 votes

Is there a way to Download all notes/attachments from a Salesforce Opportunity?

One simple app is there on salesforce called "Mass file Download". This app Download Multiple Files on a single click. It supports Mass download of Attachments, Files, Static Resource and Documents as ...
Abdul Hafeez's user avatar
4 votes
Accepted

Need to restrict <apex:inputFile> extension using jquery

The following JavaScript function can be used to validate that the type of file that a user tries to upload is of a certain format. It does this by checking that the files extention (eg .jpg) is in an ...
Saroj Bera's user avatar
  • 14.7k
4 votes
Accepted

visualforce to create a attachment for an object

Declare an Id variable. In the constructor, retrieve the Id of the record as follows: controller.getId(); With this Id, try to insert the attachment record. Change VFP code like this: <apex:...
Santanu Boral's user avatar

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