Questions tagged [contentdocumentlink]

Use this object to query the locations where a file is shared or query which files are linked to a particular location.

Filter by
Sorted by
Tagged with
51 votes
7 answers
48k views

Obtaining all ContentDocument records using SOQL

According to the Salesforce documentation on ContentDocument Users (including users with the “View All Data” permission) can only query files they have access I find this very strange. Why would a ...
GuiSim's user avatar
  • 932
12 votes
1 answer
2k views

How to distinguish between ContentDocument and ContentNote?

There seems to be some unusual stuff going on with SObjectType for the enhanced note ContentNote (ERD) object and the underling ContentDocument (ERD) structure. For example, both these return a ...
Keith C's user avatar
  • 135k
10 votes
1 answer
10k views

How to Upload a File to a specific Library Folder using Apex?

I am trying to save a Visualforce page as a PDF file to a Library folder in our Salesforce org. I have been unable to figure out how to save this new PDF file to a specific Library folder. I tried ...
user7100889's user avatar
10 votes
1 answer
7k views

How to create an EmailMessage record with DML having HasAttachment to be 'true'?

I'm creating EmailMessage records via DML EmailMessage createWhatEmail = new EmailMessage( Subject = 'test' ,Status = '3' ,ToAddress = 'heim@...
Uwe Heim's user avatar
  • 28.3k
8 votes
1 answer
1k views

ContentDocumentLink query returns different results based on LinkedEntityId size

If I want to find how many files are related to a given object (ex. Account), I could do the following two queries (assuming you don't hit a 50,000 row limit - this is just an example). //get accounts ...
Kris Goncalves's user avatar
8 votes
1 answer
647 views

Weird Behaviour of Bulk ContentDocumentLinkTrigger in Test Context

I know that ContentDocumentLink triggers are not bulkified by Salesforce. I was expecting that behavior and was writing test classes accordingly. It looks like, ContentDocumentLinkTrigger doesn't ...
Pranay Jaiswal's user avatar
7 votes
1 answer
4k views

Entity 'ContentDocumentLink' is not supported for semi join inner selects

Why doesn't Salesforce support semi join selects on the ContentDocumentLink entity? Why would there be a random entity that doesn't work like all the others? This code: List<ContentVersion> ...
Robs's user avatar
  • 9,187
7 votes
4 answers
4k views

Why SingleEmailMessage.setFileAttachments() does not create visible attachments in the Activity Tab in Lightning Experience

I'm sending emails like this: Messaging.SingleEmailMessage m = new Messaging.SingleEmailMessage(); m.setToAddresses( new String[]{'[email protected]'} ); m.setSubject( 'test' ); m.setHtmlBody( ...
Uwe Heim's user avatar
  • 28.3k
6 votes
3 answers
16k views

How to generate a download URL for a ContentDocument in Lightning Community

We're querying ContentDocumentLink for a list of documents related to a specific object record that the user has access to, and attempting to create a link for the community user to download that ...
Jerbot's user avatar
  • 161
6 votes
1 answer
8k views

ContentDocumentLink Apex after insert trigger error

Edit: I've built an after insert trigger on ContentDocumentLink. On cropredy's direction, I've bulkified my code and I think improved it generally. It "works" in that it accomplishes my ...
tim shores's user avatar
5 votes
2 answers
5k views

ContentVersion FileExtension

Does anyone know how I can change the FileExtension for a new ContentVersion in a test class? Im currently trying to create a test class for my ContentDocumentLink Trigger, in which I have an if ...
Tim Werner's user avatar
5 votes
0 answers
926 views

How can you insert a Salesforce File with Collaborator ShareType?

I am currently trying to insert a Salesforce File attached to a custom Invoice object with the Collaborator (C) permission, as described on the Salesforce Documentation. The code was originally set ...
salesForceNoob's user avatar
4 votes
1 answer
6k views

How to query ContentDocument and Custom object's fields at once?

We have 3 objects. OS_Account_Document__c (Custom) ContentDocument ContentDocumentLink I need to query two custom fields (Document_Type__c and Custom_Document_Description__c) from the Custom Object ...
Prakhar Saxena's user avatar
4 votes
1 answer
131 views

How can I prevent a ContentDocument being deleted when it is linked to a record meeting certain criteria?

I have ContentDocuments being used to capture "proof" against certifications. Once the submitted certification (and "proof") has been reviewed, that certification is marked "...
Phil W's user avatar
  • 34.3k
4 votes
1 answer
8k views

How to download files, documents (attachments) in salesforce via apex?

I want to download all files associated with records (single or multiple records) of a particular object at one click, using apex. Let's say that there is a custom object myVehicle which holds ...
Pankaj Singh's user avatar
4 votes
1 answer
511 views

Why is this ContentNote trigger receiving 1 record at a time even though multiple records are being inserted?

I am seeing a ContentNote trigger called on individual rows even though a bulk insert is done. A stripped down version follows. The debug log output demonstrates that 3 ContentNote objects are ...
Keith C's user avatar
  • 135k
4 votes
1 answer
2k views

Generate a Public Accessible link from ContentDocument

My Client wants to upload Image files from Account and generate a link for this image file and save it in a custom field on Account. This link should be Public Accessible (access from outside without ...
Dinesh Wickramasinghe's user avatar
4 votes
1 answer
2k views

ContentNote not inserting

I am trying to insert a new ContentNote and link it to an opportunity with ContentDocumentLink. However, after inserting the content note, the ID returns as NULL, so referencing it in the ...
LearningDash's user avatar
4 votes
0 answers
1k views

USING SCOPE Everything not working

I wrote a trigger on ContentDocumentlink to get a count of number of files uploaded against Service_Request__c (Custom Object) record.It works fine for new files are uploaded on Service Request record....
sfdc's user avatar
  • 13.6k
4 votes
5 answers
5k views

Document: You don't have permission to share this file

I am trying to upload a file from salesforce sites into Files and then relate it with a record using VF page. i am able to upload the file and while creating a ContentDocumentLink i am getting this ...
Prady's user avatar
  • 12.2k
3 votes
1 answer
17k views

How to query ContentDocumentLink in SOQL and then upsert records in Data Loader

When querying ContentDocumentLink in SOQL using the following query, an error is thrown. Goal: We are attempting to get a spreadsheet of the data so we can update IsDeleted flag with TRUE on entries ...
WrittenInCode's user avatar
3 votes
3 answers
7k views

Community user cannot download file

I am using an old portal for my customers, with customer community user licenses. In the portal, my users should upload files and then download the files that they have uploaded. The portal is ...
Itai Shmida's user avatar
  • 4,995
3 votes
3 answers
6k views

Unable to delete ContentDocumentLink

This is all on a Salesforce Community. I have a situation where a user is uploading a file and it's temporarily assigned to their user record. Once they submit the form and it creates a custom object ...
Tony Evans's user avatar
3 votes
2 answers
3k views

SOQL ContentDocument: Ids not returning

A handful of our users have created notes on contact and opportunity objects that we are trying to port over. They are currently saved as ContentDocuments - but I also want to pull what objects the ...
ZAR's user avatar
  • 2,013
3 votes
1 answer
3k views

How to prevent duplicate File (ContentDocument) if the same file is uploaded at multiple records?

This is a day-to-day use case: Assume there are many Opportunities on an Org. Now Sales-Reps are uploading some auxiliary information as Files in Lightning using the standard related list and there ...
Uwe Heim's user avatar
  • 28.3k
3 votes
1 answer
4k views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : [NetworkId]

I've written a simple trigger to enforce our Community users not to delete files. Currently, I'm facing an issue in getting test coverage for deployment. Trigger trigger ContentDocumentTrigger on ...
Salesforce Developer's user avatar
3 votes
1 answer
3k views

ContentDocumentID is not available just after ContentVersion getting inserted But available after soql query

I am inserting ContentVersion as following:- String yourFiles = 'Lets assume this is your binary string of the files'; ContentVersion conVer = new ContentVersion(); conVer.ContentLocation = 'S'; // S ...
sanket kumar's user avatar
3 votes
2 answers
4k views

LinkedEntityid is the user incorrectly coming in ContentDocumentLink trigger

I am creating a trigger on ContentDocumentLink and I am attaching a file via upload file option in related list to a record. In trigger(after insert), the linkEntityId is generated as user id but I ...
Prakash Chandra's user avatar
3 votes
1 answer
711 views

ContentDocumentLink trigger not running

I've been trying to track down why a ContentDocumentLink trigger is not running in a specific case. In the working cases we have code that inserts ContentDocumentLink records, but in the failing case ...
Keith C's user avatar
  • 135k
3 votes
1 answer
160 views

Incorrect result for ContentDocumentLink query

I'm trying to query all the ContentDocumentLinks related to a list of about 25000 accounts. This yields no results. However, if I limit the initial account query to only 800 accounts I do find a ...
Kasper's user avatar
  • 2,872
3 votes
1 answer
1k views

Create new ContentVersion with ContentDocumentLink to non-user only

Every time I create a new ContentVersion without ContentDocumentId it automatically creates a ContentDocumentLink that is linked to the user. I just want it to link to an Opportunity so I'm not sure ...
Semmel's user avatar
  • 2,272
3 votes
0 answers
46 views

Mismatched LInkedEntityId on ContentDocumentLinks

I'm trying to link attachment files to Salesforce EmailMessages. Steps so far: Upload attachment file by posting to /services/data/v58.0/sobjects/ContentVersion. Query ContentVersion table to get ...
Alex's user avatar
  • 31
3 votes
0 answers
340 views

ContentDocumentLink SOQL doesn't return all rows

I have the same question as this one (but couldn't comment on it) To reproduce the issue: Map<Id, Contract> limitedContracts = new Map<Id, Contract>([ SELECT Id FROM Contract ...
Peter Yao's user avatar
3 votes
0 answers
302 views

How to determine if the user has enough permissions to Share ContentDocument to sObject

I have a situation that seems to be consistent with the top comments here: https://success.salesforce.com/ideaview?id=087300000006n4GAAQ Specifically, i have a Content Workspace aka Content Library, ...
zaitsman's user avatar
  • 1,890
3 votes
0 answers
400 views

SOQL query in Trigger returns no results but returns a row in Developer Console

I have the following code snippet in a Helper class that's being called by an After Insert trigger (modified to demonstrate my objective): Set<Id> reuseIds = new Set<Id>(); reuseIds.add('...
mchandler's user avatar
  • 130
3 votes
0 answers
432 views

While adding new contentDocumentLink Contentdocuments lastmodifieddate is getting changed. How we can stop that

I am migrating attachment records to contentVersion. I am also updating created and lastmodified date of new contentversion records from Attachment record. It is getting updated fine. But when I am ...
Manjot Singh's user avatar
  • 3,408
3 votes
0 answers
3k views

ContentDocumentLink - Can't set Visibility:InternalUsers when linking to case in specific sandbox

I have to push about 40,000 files into Salesforce as case files for a go live cutover. I have a process which creates a ContentVersion and then a ContentDocumentLink. In one sandbox, the files are ...
The Evil Greebo's user avatar
2 votes
1 answer
3k views

ContentDocumentLink filter not working- Trailhead Conference Management App

Im facing below error: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN ...
Priya's user avatar
  • 115
2 votes
1 answer
410 views

Apex Error "Too Many SOQL Queries" with Trigger on ContentDocumentLink

I'm getting the "Too many SOQL queries: 101" when executing a test class. I'm not even getting into my test method - it's failing on the test setup. When it fails, it's failing in my trigger ...
Jeff's user avatar
  • 133
2 votes
1 answer
394 views

Why Blob equals doesn't work if one of the Blobs is retrieved from ContentDocument?

In brief, I can't test the value stored in a ContentDocument. Even if the value of the two Blobs is the exact same, equals would return false. Do someone know the reason? Here's a unit test to check ...
Francesco Pitzalis's user avatar
2 votes
1 answer
2k views

Scheduled Data Export: how to obtain ContentVersion linking data

I've used the Data Export feature to pull down ContentVersion data for Files and (Enhanced) Notes from a Salesforce org that's being migrated into a different org. I've been unable to locate the ...
David Reed's user avatar
  • 92.1k
2 votes
1 answer
134 views

Help with sorting content documents by custom field on its LinkedEntity

This SOQL statement works, but I'm trying to sort the Content Documents by a field e.g. Sort_Order__c on Invoice__c. SELECT ContentDocument.id,LinkedEntity.Name,LinkedEntityId FROM ContentDocumentLink ...
Dan Hardy's user avatar
2 votes
1 answer
2k views

"Unable to create/update fields: VersionData" error when updating a ContentNote from Apex

I have some Apex code that inserts a ContentNote and the corresponding ContentDocumentLink. This works fine and the data can be viewed through the normal Salesforce UI. But some further code that ...
Keith C's user avatar
  • 135k
2 votes
1 answer
45 views

Create ContentDocumentLink after insert ContentDocument error

I have pretty simple requirement but I am facing error and I can't understand what is going wrong. I need to add ContentDocumentLink to add file to CollaborationGroup after insert with C permission. I ...
Maciej's user avatar
  • 45
2 votes
1 answer
50 views

Perplexing ContentDocumentLink SOQL issue

I have the following code: // Note: cdlToDos == Map<Id, Set<decimal>> System.debug(cdlToDos); List<ContentDocumentLink> cdlList = [ SELECT Id, ContentDocumentId, LinkedEntityId ...
Ixalmida's user avatar
  • 311
2 votes
2 answers
3k views

Move a ContentDocument from one library to another in Apex

Is there a direct way to do this in Apex? I tried doing DML to ContentDocumentLink or ContentWorkspaceDoc. But nothing works. What I tried so far Update the Library in ContentWorkspaceDoc ...
k Walker's user avatar
2 votes
1 answer
924 views

How to query contentversion to Email Message

We have integrated Salesfroce and our Support Page, and I have to send emailmessage via rest api along with attachment lies within the email, but I don't find a relateionship between Contentversion ...
Manoj kumar's user avatar
2 votes
1 answer
2k views

Public guest user can't access ContentDocuments

I have a site with a Visualforce page that requires access to ContentDocuments linked to an Opportunity. My problem is that i can only see, as a public guest user, content documents that are uploaded ...
user37586's user avatar
  • 660
2 votes
0 answers
505 views

Visibility InternalUsers is not permitted for this linked record only in Test context

I am receiving the following message when trying to insert a ContentDocumentLink in a trigger but only in test context : Visibility InternalUsers is not permitted for this linked record I checked ...
THEDJA's user avatar
  • 125
2 votes
0 answers
221 views

File not showing preview when created by Force.com Site Guest User (i think after Summer '20 Release)

I saw that since Summer 20 changes to the rights of the Force.com Site have taken place (https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_networks_guest_user.htm) Currently I ...
arnaud's user avatar
  • 104

1
2 3 4 5