Renaming multiple folders easily
Hi, I was wondering if there is a way to rename around 500 folders with the same name easily. There is 500 folders and withing each folder there is a folder with the same name. That folder needs to be renamed.
-
This can be done by creating a script using our API. The specific endpoint you would need to update the name would be: https://developer.box.com/reference#update-information-about-a-folder. However, you would first need to find all the folder IDs of the folders with the same name. Perhaps someone else might be able to provide more details on that piece!
Best of luck,
Kourtney
-
Thanks, I was looking for a way to do it in apex. I have box integrated on salesforce.
// Instantiate the Toolkit object box.Toolkit toolkit = new box.Toolkit(); // Get the Salesforce record id associated with a Box folder String recordId = toolkit.getRecordIdByFolderId('{some folder id}'); //folderNameOverride('some name'); Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://developer.box.com/v2.0/reference#folder-object' + id); request.setMethod('PUT'); request.setHeader('X-HTTP-Method-Override','PATCH'); request.setTimeout(6000); HttpResponse response = http.send(request);
-
Have you had a look at the Box Salesforce SDK?
BoxFolder folder = new BoxFolder(api, 'folder-id'); folder.rename('New Name');
....or you can update the information for a folder as below:
BoxFolder folder = new BoxFolder(api, 'folder-id'); BoxFolder.Info info = folder.new Info(); info.addValue('description', 'Some folder I made'); info.addValue('name', 'New Folder Name'); folder.updateFolderInfo(info);
As mentioned you will need to first get the folder Ids of all of the folders to be renamed
BoxFolder folder = new BoxFolder(api, 'folder-id'); list children = folder.getChildren(); for (BoxItem.Info itemInfo : children) { if (itemInfo.getObjectType() == 'folder') { // Do something with the folder } else if (itemInfo.getObjectType() == 'file') { // Do something with the file } }
* Note: A call to getChildren() will return the contents of a BoxFolder. Optionally, an offset and limit can be set to iterate over a large folder. Large folder operations will likely fail due to governor limits on callouts or heap size. This method could be detrimental depending on your use case
Please sign in to leave a comment.
Comments
3 comments