You need to sign in to do that
Don't have an account?

how can I fetch all files attached to a Case object.
Hi, I'd like to ask how can I fetch all files attached to a Case object. I'm using Lightning mode.
I don't seem to find where exactly ContentVersion, ContentDocument and ContentDocumentLink are somehow relates to Case object.
I'm looking for a way to locate and download all attachments based on a query where my input is Case number or case ID
Thanks in advance
Uri
I don't seem to find where exactly ContentVersion, ContentDocument and ContentDocumentLink are somehow relates to Case object.
I'm looking for a way to locate and download all attachments based on a query where my input is Case number or case ID
Thanks in advance
Uri
Review below link which can explain on how to fetch attachments on case object.
https://developer.salesforce.com/forums/?id=906F000000090ugIAA
https://trailblazers.salesforce.com/answers?id=9063A000000DY0GQAW
Thanks,
Vinay Kumar
Thanks for you quick response.
Query in line 19 seem to be not completed. I don't see its "FROM" and "WHERE" part.
Please advise.
Uri
Thanks for your quick response.
You are referring to "Attachment" object, which is not relevant, AFAIK, to Lightning mode which I'm using.
Please advise if you have an approach for Lightning mode.
Uri
for the specific line, it is as below:
List<ContentNote> contentNotes = [SELECT Id,Title,Content,TextPreview,CreatedDate,LastModifiedDate,CreatedBy.name,
CreatedBy.Id,LastModifiedBy.Name FROM ContentNote
WHERE ID in :contentVersionIds ORDER BY LastModifiedDate DESC];
Thanks for your help.
I tried to perform a query of: SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :caseId
But once I put a 'Case' object ID there, the system returns with an answer that there are no records that match.
I did notice that the above query workes only if I use ID of object of type 'ContentWorkspace' .
Does it makes any sense?
Uri
But if you run the code I provided through controller, it should return the expected result without "Query All Files" permission.
And while connecting to DB, I'm using a user with high enough permissions. and even though, I get nothing in return from first query, which is the exact query you advised, and it is also the one that start all process based on a given Case object.
Any other suggestions?
Thanks in advance
I added the needed permission to my account.
I now see that the third query doesn't return any records. I noticed that it is looking in an object called ContentNote. Why is specifically this object is needed to get all attached files?
isn't it suppose to be contentVertion object that holds the data?
could you please explain what is the porpuse of the third query?
thanks
Here is the updated code.
I made a progress thanks to you!
Now I can reach some attachments objects which are attached to a given Case.
But, once I entered via browser to inspect the Case object, I noticed that I can see only 3 ContentDocumentId objects (meaning 3 attachments) while actually I can see many more files attached to this Case while inspecting it from attachments tab from browser (and not by performing SOQL queries via PHP)
the thing is that the user I'm using while performing PHP SOQL to SalesForce DB has much more privileges than those I have with my own user which I use to inspect Case manually object via browser - thus I concluded that it is not a permissions issue but something else.
Any idea?
Thanks in advance.
Among the files I do see, they are .txt files, all other files which I don't see from SOQL query output are .jpg
does it makes any sense?
You can test this by using the following soql:
Select ID,Body,ContentType,Name from Attachment where parentId = :caseId
2. regarding .txt file issue,
You can add a field in line 10 query to get the file extension. It should contain all types of the extension.
List<ContentVersion> contentVersions = [SELECT Id,ContentDocumentId,Title,FileExtension,VersionData,isLatest FROM ContentVersion WHERE ContentDocumentId in :contentDocumentLinkIds and FileType!='SNOTE' and IsLatest = true];
On this case, you need to get all EmailMessages related to that Case, to then query the ContentDocumentLink based on related email ids.