I understand that there are several approaches to get content version data.
public with sharing class ContentVersionService {
public static Blob getContent(ContentVersion cv) {
Http h = new Http();
HttpRequest r0 = new HttpRequest();
r0.setMethod('GET');
r0.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v47.0/sobjects/ContentVersion/0681x000001p65tAAA/VersionData');
r0.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HTTPResponse res0 = h.send(r0);
System.debug(LoggingLevel.ERROR, '@@@ : status' + res0.getStatus());
System.debug(LoggingLevel.ERROR, '@@@ : status' + res0.getStatusCode());
System.debug(LoggingLevel.ERROR, '@@@ : keys' + res0.getHeaderKeys());
for (String key: res0.getHeaderKeys()) {
System.debug(LoggingLevel.ERROR, '@@@ : key: ' + key + ' header = ' + res0.getHeader(key));
}
System.debug(LoggingLevel.ERROR, '@@@ : ' + res0.getBody());
return res0.getBodyAsBlob();
}
}
However, there are two drawbacks on this approach. First, it requires Remote Site Settings to be added manually for every client who might use this code, so it doesn't see a viable solution for ISV.
Second, it doesn't work with Lightning Session Id.
When a user tries to use this approach, an error message is returned
[{"message":"This session is not valid for use with the REST API","errorCode":"INVALID_SESSION_ID"}]
Another suggested approach is to query ContentNote.
Id contentDocId = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = 'recId '];
ContentNote cn = [ select id,Title,CreatedDate, Content,TextPreview from ContentNote Where Id = 'contentDocId' ]; // gives value of note body and title
However, this approach doesn't work for me at all because it throws an error
[INVALID_TYPE] sObject type 'ContentNote' is not supported.
Does anyone know or have a clues if is this possible to get content version data without making self callout?