services/data/vXX.X/sobjects/ContentVersion
//Creare il documento
//Nota: in questo esempio, il contenuto viene creato in Apex
//In alternativa, è possibile caricare il contenuto tramite Data Loader.
ContentVersion cv = new ContentVersion();
cv.Title = 'Test Document';
cv.PathOnClient = 'TestDocument.pdf';
cv.VersionData = Blob.valueOf('Test Content');
cv.IsMajorVersion = true;
Insert cv;
//Ottenere i documenti contenuto
Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
//Creare ContentDocumentLink
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = conDocId;
//L'etichetta contiene l'ID utente dell'utente integrazione Cloud (ottenuta separatamente)
cdl.LinkedEntityId = Label.Platform_User_Id;
//V - Autorizzazione Visualizzatore. C - Autorizzazione Collaboratore. I - Autorizzazione implicita
cdl.ShareType = 'V';
Insert cdl;
CloudIntegrationUser.Il nome dell'utente integrazione Cloud è cloud@ + orgId di 18 caratteri in minuscolo. Vedere la query SOQL seguente
SELECT Id, UserName from User WHERE username like 'cloud@00d%'
// Selezione intenzionale di un altro file NON di proprietà dell'utente integrazione piattaforma
// (Id dell'utente integrazione piattaforma hardcoded, da sostituire con un ID più dinamico
// unire nella query)
let contentQuery = "SELECT Id
FROM ContentVersion
WHERE OwnerId != '0055f0000057ROYAA2'
ORDER BY CreatedDate DESC LIMIT 1";
let queryResults = await context.org.dataApi.query(contentQuery);
let contId = "";
for (const downItem of queryResults.records) {
contId = downItem.fields["Id"];
break;
}
// ID file per il download
logger.info("contId: " + JSON.parse(JSON.stringify(contId)));
// Stampare
logger.info("DOWNLOAD LATEST FILE NOT OWNED BY FUNCTIONS USER");
await request
.get(
context.org.baseUrl +
"/services/data/v54.0/sobjects/ContentVersion/" +
contId +
"/VersionData"
)
.auth(null, null, true, context.org.dataApi.accessToken)
.on("error", function (err) {
logger.info("Exception: " + err);
})
.pipe(
fs.createWriteStream("./tempFiles/downFile.csv", { encoding: "utf8" })
)
.on("finish", doSomethingAfterDownload);
}
Platform_User_Id dell'esempio precedente, necessario per la creazione del link al documento).trigger ContentVersionTrigger on ContentVersion (after insert) {
ContentVersionTriggerHelper.triggerHelper(
Trigger.operationType,
Trigger.new,
Trigger.oldMap);
}
public with sharing class ContentVersionTriggerHelper {
public static void triggerHelper(
System.TriggerOperation operationType,
List<ContentVersion> newList,
Map<Id, ContentVersion> oldMap
) {
switch on operationType {
when AFTER_INSERT{
List<ContentVersion> docsToProcess = getDocsToShare(newList);
if(!docsToProcess.isEmpty()){
shareWithIntegrationUser(docsToProcess);
}
}
}
}
public static List<ContentVersion> getDocsToShare(List<ContentVersion> allDocuments){
List<ContentVersion> docsToProcess = new List<ContentVersion>();
for(ContentVersion cVer : allDocuments){
if(cDoc.OwnerId != Label.Platform_User_Id){
docsToProcess.add(cVer);
}
}
return docsToProcess;
}
public static void shareWithIntegrationUser(List<ContentVersion> documents){
List<ContentDocumentLink> shareLinks = new List<ContentDocumentLink>();
for(ContentVersion cVer : documents){
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = cVer.ContentDocumentId;
cdl.LinkedEntityId = Label.Platform_User_Id;
cdl.ShareType = 'V';
shareLinks.add(cdl);
}
Database.insert(shareLinks,false);
}
}
000393095

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.