6

According to the release notes Lightning Experience Limitations, attachments uploaded in lightning aren't the same as attachments uploaded through salesforce classic. Notes and attachments in lightning

How can i query for the lightning attachment in SOQL?

8

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 record .

SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]'

Then SOQL on ContentDocument

Select Id ,Title from ContentDocument Where ID In :[CONTENTDOCUMENTLIST]
| improve this answer | |
  • How could this be done on a mass scale? – Tyler Zika Dec 15 '17 at 21:33
  • Or combine both queries? select Id, Title from ContentDocument where Id in (select ContentDocumentId from ContentDocumentLink where LinkedEntityId = '[RECORD ID]') – dana May 24 '18 at 10:28
3

In lightning when you upload attachments, it save as salesforce files. for querying salesforce files you need to understand three object:

  1. ContentVersion
  2. ContentDocumentLink
  3. ContentDocument

for each files uploaded in lightning, there will be only one contentDocument will get created. Contentversion depends upon you, default it will get create as version 1, later you can create n number of contentVersion. If you are uploading the document on a record, there will be two contentDocumentLink will get created. One will be related to you and other will be related to that particular record. later if you share the file with any other record or user, for each one, a contentDocumentlink will get created.

You can query all the latest contentversion as:

[select id,FileType, Title,FileExtension, Versiondata from ContentVersion where islatest=true ];

for querying the no. of files related to a particular record:

[SELECT Id, LinkedEntityId, ContentDocumentId,Visibility, IsDeleted, ShareType,ContentDocument.Title,ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE LinkedEntityId =:parentIds and ContentDocument.FileType!= 'SNOTE'];

ContentDocument.FileType!= 'SNOTE' this will help you to eliminate the contentNote .

for querying ContentDocument directly:

[Select Id,FileExtension,SharingOption,Title from ContentDocument ];
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.