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!