services/data/vXX.X/sobjects/ContentVersion
//ドキュメントを生成します。
//メモ:この例では Apex でコンテンツを作成します
//データローダを使用してコンテンツをロードすることもできます。
ContentVersion cv = new ContentVersion();
cv.Title = 'Test Document';
cv.PathOnClient = 'TestDocument.pdf';
cv.VersionData = Blob.valueOf('Test Content');
cv.IsMajorVersion = true;
Insert cv;
//コンテンツドキュメントを取得します。
Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
//ContentDocumentLink を作成します。
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = conDocId;
//ラベルにはクラウドインテグレーションユーザーのユーザー ID (別途取得) が含まれます。
cdl.LinkedEntityId = Label.Platform_User_Id;
//V - 閲覧者権限。C - コラボレータ権限。I - 推定される権限
cdl.ShareType = 'V';
Insert cdl;
CloudIntegrationUser のユーザー名を特定できます。クラウドインテグレーションユーザー名は cloud@ + 小文字 18 文字の orgId です。次の SOQL クエリを参照してください。
SELECT Id, UserName from User WHERE username like 'cloud@00d%'
// プラットフォームインテグレーションユーザーが所有していない別のファイルを意図的に選択します
// (ハードコード化されたプラットフォームインテグレーションユーザー ID。より動的な ID に置き換えられます
// クエリでマージします)
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
logger.info("contId: " + JSON.parse(JSON.stringify(contId)));
// 印刷
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 が必要です)。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.