0

I try to query the newest ContentDocumentLink on a record. My approach is pretty simple. I want ORDER BY CreatedDate and LIMIT 1.

ContentDocumentLink cdl = [SELECT Id FROM ContentDocumentLink WHERE LinkedEntityId = :linkedEntityId ORDER BY CreatedDate DESC LIMIT 1]

However, I get an error that there is no such column CreatedDate on entity ContentDocumentLink:

No such column 'CreatedDate' on entity 'ContentDocumentLink'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

My current workaround is to order by createddate of the ContentDocument. However this includes the risk of failing when a document is assigned to the record late.

How can I get the latest ContentDocumentLink on my record?

Thanks in Advance!

1
  • I think you will have to refer ContentModifiedDate on ContentDocument object.
    – Elijah
    Apr 3, 2023 at 16:41

1 Answer 1

2

As you can see from Workbench, there is no CreatedDate on ContentDocumentLink

enter image description here

You can use SystemModstamp for sorting

Difference between LastModifiedDate and SystemModstamp

2
  • This type of information is also (usually) available if you search for "X object reference" in your search engine of choice. To wit, developer.salesforce.com/docs/atlas.en-us.object_reference.meta/…
    – Derek F
    Apr 3, 2023 at 17:46
  • 1
    Sadly, for System Fields, the Object Reference on a per object basis is not helpful; these system fields are covered in this doc ref and I've found you have to do a describe to check on edge cases like ContentDocumentLink
    – cropredy
    Apr 3, 2023 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .