Hi @peifengyuan!
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.
New Dev Toolkit Metadata CRUD Methods:
- box.FolderMetadata createBoxMetadataByFolderId(String folderId, String scope, String template_key, List<box.KeyValuePair> keyValuePairs)
- box.FolderMetadata getBoxMetadataByFolderId(String folderId, String scope, String template_key)
- box.FolderMetadata updateBoxMetadataByFolderId(String folderId, String scope, String template_key, List<box.FolderMetadataUpdate> mdUpdates)
- Boolean deleteBoxMetadataByFolderId(String folderId, String scope, String template_key)
box.KeyValuePair Class
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!
Hi @kadams !
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.
Thank you again and Hope you have a greate day!!
Thank you & Best Regards,
peifeng yuan