0

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> contentVersions = [SELECT VersionData 
                                        FROM ContentVersion 
                                        WHERE ContentDocumentId 
                                        IN (SELECT ContentDocumentId                                  
                                            FROM ContentDocumentLink 
                                            WHERE LinkedEntityId = :recordId)
                                        ORDER BY CreatedDate DESC LIMIT 1];

Throws this error:

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

  • as a workaround:- Use this:- select VersionData from Contentversion where ContentDocumentId in (select id from ContentDocument) – sanket kumar Sep 6 '18 at 3:39
2

Some objects have an insanely high SOQL cost, so they're simply not allowed. For example, you also can't do semi-join selects on Task or Activity, either. The performance cost is simply too great. In those cases, you need to query one object, gather all the related ID values, then query the related object. It's annoying, and rather useless most of the time, but it's there to prevent developers from querying potentially hundreds of tables.

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.