Could you please provide guidance on how to use the API (Update metadata instance on folder:PUT) using Apex?
For Create metadata instance on folder(POST), I was able to achieve it as described above. However, I’m unsure how to set the Body for Update metadata instance on folder.
Sample Code for Use Create metadata instance on folder(POST)
box.Toolkit toolkit = new box.Toolkit();
String folderId = project.ProjectFolderId__c;
There are actually some brand new Dev Toolkit apex methods and corresponding Flow invocable actions that were released recently, but our documentation has not been updated yet.
global class KeyValuePair {
@AuraEnabled
global String key;
@AuraEnabled
global String value;
global KeyValuePair() {
}
}
box.FolderMetadataUpdate Class
global class FolderMetadataUpdate {
@AuraEnabled
global String op;
@AuraEnabled
global String path;
@AuraEnabled
global String value;
global FolderMetadataUpdate() {
}
Here is an example of creating a metadata instance on a folder:
box.Toolkit toolkit = new box.Toolkit();
String folderId = '216484150697';
String accountId = '001Dm000005NJVXIA4';
List<box.KeyValuePair> mdKeyValues = new List<box.KeyValuePair>();
Account acct = [SELECT Id, Name FROM Account WHERE Id = :accountId LIMIT 1];
if(acct != null) {
box.KeyValuePair accountId = new box.KeyValuePair();
accountId.key = 'accountId';
accountId.value = acct.Id;
mdKeyValues.add(accountId);
box.KeyValuePair accountName = new box.KeyValuePair();
accountName.key = 'accountName';
accountName.value = acct.Name;
mdKeyValues.add(accountName);
box.FolderMetadata folderMeta = toolkit.createBoxMetadataByFolderId(folderId, 'enterprise', 'account', mdKeyValues);
System.debug('Added folder metadata: ' + folderMeta);
}
And here is an example of updating the metadata instance on a folder:
box.Toolkit toolkit = new box.Toolkit();
String folderId = '216484150697';
String accountId = '001Dm000005NJVXIA4';
List<box.FolderMetadataUpdate> mdUpdates = new List<box.FolderMetadataUpdate>();
Account acct = [SELECT Id, Name FROM Account WHERE Id = :accountId LIMIT 1];
if(acct != null) {
box.FolderMetadataUpdate mdUpdate = new box.FolderMetadataUpdate();
mdUpdate.op = 'replace';
mdUpdate.path = '/accountName';
mdUpdate.value = 'This is my new Account Name';
mdUpdates.add(mdUpdate);
box.FolderMetadata folderMeta = toolkit.updateBoxMetadataByFolderId(folderId, 'enterprise', 'account', mdKeyValues);
System.debug('Updated folder metadata: ' + folderMeta);
}
I hope this helps! Let us know if you have any additional questions!
Thank you for providing the sample code.
I have reviewed the release notes and implemented it using the API since it was not mentioned in the documentation.
I appreciate your assistance and will refer to the code as a reference.