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 ...
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
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, ...
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}" />
...
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
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
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
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
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 ...
6
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://...
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 ...
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 ...
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....
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 ...
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>());...
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 ...
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',
...
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....
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
attachment × 714apex × 213
visualforce × 142
email × 72
trigger × 56
files × 56
pdf × 51
rest-api × 37
soql × 35
notes × 27
contentdocument × 25
case × 22
lightning × 21
data-loader × 21
blob × 20
custom-object × 18
upload × 18
lightning-aura-components × 17
contentversion × 16
images × 15
community × 14
emailfileattachment × 14
lightning-web-components × 13
javascript × 13
csv × 13