Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Update a Repository File with Content
Call a method to update a repository file with content.
Call updateRepositoryFile(repositoryId, repositoryFileId, file, fileData) to
update the content and metadata of a file in a repository. After the file is updated, we show
the file’s ID, name, description, external URL, and download
URL.
1final String gDriveRepositoryId = '0XCxx00000000ODGAY', gDriveFolderId = 'folder:0B0lTys1KmM3sSVJ2bjIzTGFqSWs', gDriveFileId = 'document:1q9OatVpcyYBK-JWzp_PhR75ulQghwFP15zhkamKrRcQ';
2
3final ConnectApi.ContentHubItemInput updatedItem = new ConnectApi.ContentHubItemInput();
4updatedItem.itemTypeId = 'document'; //see getAllowedTypes for any file item types available for creation/update
5updatedItem.fields = new List<ConnectApi.ContentHubFieldValueInput>();
6
7//Metadata: name field
8final ConnectApi.ContentHubFieldValueInput fieldValueInputName = new ConnectApi.ContentHubFieldValueInput();
9fieldValueInputName.name = 'name';
10fieldValueInputName.value = 'updated file name.txt';
11updatedItem.fields.add(fieldValueInputName);
12
13//Binary content
14final Blob updatedFileBlob = Blob.valueOf('even more awesome content for updated file');
15final String updatedFileMimeType = 'text/plain';
16final ConnectApi.BinaryInput fileBinaryInput = new ConnectApi.BinaryInput(updatedFileBlob, updatedFileMimeType, updatedFileName);
17
18final ConnectApi.RepositoryFileDetail updatedFile = ConnectApi.ContentHub.updateRepositoryFile(gDriveRepositoryId, gDriveFileId, updatedItem);
19System.debug(String.format('Updated file - id: \'\'{0}\'\', name: \'\'{1}\'\', description: \'\'{2}\'\',\n external URL: \'\'{3}\'\', download URL: \'\'{4}\'\'', new String[]{ updatedFile.id, updatedFile.name, updatedFile.description, updatedFile.externalDocumentUrl, updatedFile.downloadUrl}));