7

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

1
  • 1
    as a workaround:- Use this:- select VersionData from Contentversion where ContentDocumentId in (select id from ContentDocument) Sep 6, 2018 at 3:39

1 Answer 1

13

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

You must log in to answer this question.

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