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.
Create a Repository File with Content
Call a method to create a file with binary content in a Google Drive repository
folder.
Call addRepositoryItem(repositoryId, repositoryFolderId, file, filedata) to
create a file with binary content in a Google Drive repository folder. After the file is
created, we show the file’s ID, name, description, external URL, and download
URL.
1final String gDriveRepositoryId = '0XCxx00000000ODGAY', gDriveFolderId = 'folder:0B0lTys1KmM3sSVJ2bjIzTGFqSWs';
2
3final ConnectApi.ContentHubItemInput newItem = new ConnectApi.ContentHubItemInput();
4newItem.itemTypeId = 'document'; //see getAllowedTypes for any file item types available for creation/update
5newItem.fields = new List<ConnectApi.ContentHubFieldValueInput>();
6
7//Metadata: name field
8Final String newFileName = 'new folder item name.txt';
9final ConnectApi.ContentHubFieldValueInput fieldValueInput = new ConnectApi.ContentHubFieldValueInput();
10fieldValueInput.name = 'name';
11fieldValueInput.value = newFileName;
12newItem.fields.add(fieldValueInput);
13
14//Metadata: description field
15final ConnectApi.ContentHubFieldValueInput fieldValueInputDesc = new ConnectApi.ContentHubFieldValueInput();
16fieldValueInputDesc.name = 'description';
17fieldValueInputDesc.value = 'It does describe it';
18newItem.fields.add(fieldValueInputDesc);
19
20//Binary content
21final Blob newFileBlob = Blob.valueOf('awesome content for brand new file');
22final String newFileMimeType = 'text/plain';
23final ConnectApi.BinaryInput fileBinaryInput = new ConnectApi.BinaryInput(newFileBlob, newFileMimeType, newFileName);
24
25final ConnectApi.RepositoryFolderItem newFolderItem = ConnectApi.ContentHub.addRepositoryItem(gDriveRepositoryId, gDriveFolderId, newItem, fileBinaryInput);
26final ConnectApi.RepositoryFileSummary newFile = newFolderItem.file;
27System.debug(String.format('New file - id: \'\'{0}\'\', name: \'\'{1}\'\', description: \'\'{2}\'\' \n external URL: \'\'{3}\'\', download URL: \'\'{4}\'\'', new String[]{ newFile.id, newFile.name, newFile.description, newFile.externalDocumentUrl, newFile.downloadUrl}));