Skip to content

SEL_ContentVersion ​

Class · Group: Selectors

Learn it: Fast Start - Selectors and Selectors guide

apex
global inherited sharing class SEL_ContentVersion extends SEL_Base

Extends: SEL_Base

Selector for the ContentVersion object. Provides query methods for retrieving content versions by publishing location, content document, and workspace folders.

Example

apex
List<ContentVersion> versions = new SEL_ContentVersion().findByFirstPublishLocationId(recordId);
List<ContentVersion> latest = new SEL_ContentVersion().findLatestByContentDocumentId(documentIds);
ContentVersion version = (ContentVersion)new SEL_ContentVersion().findById(versionId);

See Also: SEL_Base


Methods ​

MethodDescription
global List<ContentVersion> findByFirstPublishLocationId(Id firstPublishLocationId)Retrieves the latest ContentVersion records linked to the specified FirstPublishLocationId.
global List<ContentVersion> findByFirstPublishLocationId(Set<Id> firstPublishLocationIds)Retrieves the latest ContentVersion records linked to the specified FirstPublishLocationId values.
global List<ContentVersion> findLatestByContentDocumentId(Set<Id> contentDocumentIds)Retrieves the latest ContentVersion records for the specified ContentDocument IDs.
global List<ContentVersion> getAll()Retrieves all ContentVersion records in the system.
global override List<SObjectField> getFields()Returns the default fields for ContentVersion queries.

findByFirstPublishLocationId ​

apex
global List<ContentVersion> findByFirstPublishLocationId(Id firstPublishLocationId)

Retrieves the latest ContentVersion records linked to the specified FirstPublishLocationId.

Parameters

ParameterTypeDescription
firstPublishLocationIdIdThe ID of the location where the content version was first published.

Returns ContentVersion — List of the latest ContentVersion records associated with the specified location.

Example

apex
List<ContentVersion> result = instance.findByFirstPublishLocationId(recordId);
apex
global List<ContentVersion> findByFirstPublishLocationId(Set<Id> firstPublishLocationIds)

Retrieves the latest ContentVersion records linked to the specified FirstPublishLocationId values.

Parameters

ParameterTypeDescription
firstPublishLocationIdsSetSet of IDs for the locations where the content versions were first published.

Returns ContentVersion — List of ContentVersion records found for the specified locations.

Example

apex
List<ContentVersion> result = instance.findByFirstPublishLocationId(recordIds);

findLatestByContentDocumentId ​

apex
global List<ContentVersion> findLatestByContentDocumentId(Set<Id> contentDocumentIds)

Retrieves the latest ContentVersion records for the specified ContentDocument IDs.

Parameters

ParameterTypeDescription
contentDocumentIdsSetSet of Content Document IDs for which to retrieve the latest content versions.

Returns ContentVersion — A list of the latest ContentVersion records corresponding to each provided ContentDocument ID.

Example

apex
List<ContentVersion> result = instance.findLatestByContentDocumentId(recordIds);

getAll ​

apex
global List<ContentVersion> getAll()

Retrieves all ContentVersion records in the system. This method only returns data when called during a test context.

Returns ContentVersion — A list of all ContentVersion records if in a test context; otherwise, returns an empty list.

Example

apex
List<ContentVersion> allVersions = new SEL_ContentVersion().getAll();

getFields ​

apex
global override List<SObjectField> getFields()

Returns the default fields for ContentVersion queries.

Returns SObjectField — List of SObjectField tokens to include in queries.

Example

apex
List<SObjectField> result = instance.getFields();

Constructors ​

ConstructorDescription
global SEL_ContentVersion()Reads ContentVersion records, the versions of files stored in the org.

SEL_ContentVersion() ​

apex
global SEL_ContentVersion()

Reads ContentVersion records, the versions of files stored in the org. Every query skips the running user's object and field permission checks (system mode). Record sharing follows the class that calls the selector. Creating the selector runs no query.

Example

apex
SEL_ContentVersion instance = new SEL_ContentVersion();