global class CreateFolderInvocableHandler { global static Map staticMapForUseInNextTxn = new Map(); global class DriveAutomateRequest { @InvocableVariable(placeholderText='Name of the folder' required=true) global String folderName; @InvocableVariable(placeholderText='Parent folder Id (Optional)') global String parentFolderId; @InvocableVariable(placeholderText='Name of the cloud service (eg. Google Drive)' required=true) global String storageType; @InvocableVariable(placeholderText='Id of the drive') global String driveId; @InvocableVariable(placeholderText='Id of the salsesforce record' required=true) global Id recordId; } @InvocableMethod(label='FME: Create Folder')// iconName='resource:FileMadeEasyIcons:FME') public static List handleOperation(List request) { List results = new List(); try { String newAccessTokenGnt; DriveAutomateResult result = new DriveAutomateResult(); Map returnmap = new Map(); System.debug('apex class ' + JSON.serializePretty(request)); if (request != null && !request.isEmpty()) { returnmap = (Map) InvocableApexActionHandler.createFolderFromAction( true, null, request[0].folderName, request[0].parentFolderId, String.valueOf(request[0].recordId), staticMapForUseInNextTxn.get('accesstoken') ); } if (request != null && !request.isEmpty() && request[0].recordId != null) { result.recordId = request[0].recordId; result.driveId = request[0].driveId; result.storageType = request[0].storageType; } System.debug('return map ' + returnmap); if (returnmap.containsKey('parentFolderId')) { result.folderId = returnmap.get('parentFolderId'); } if (returnmap.containsKey('folderName')) { result.folderName = returnmap.get('folderName'); } if (returnmap.containsKey('isnewAccesstoken') && returnmap.get('isnewAccesstoken') == 'true') { staticMapForUseInNextTxn.put('accesstoken', returnmap.get('newAccessToken')); newAccessTokenGnt = staticMapForUseInNextTxn.get('accesstoken'); } results.add(result); String userName = UserInfo.getName(); System.debug('username>>>' + userName); String logMsg = userName + ' created folder "' + request[0].folderName + (String.isNotBlank(request[0].parentFolderId) ? ('" under parentId ' + request[0].parentFolderId): '" at root'); System.debug('logmsg>>>.'+ logMsg); FME_Logger.audit('Create Folder', logMsg, 'CreateFolderInvocableHandler', 'handleOperation'); } catch (Exception e) { FME_Logger.error(e.getMessage(), 'CreateFolderInvocableHandler' + e.getLineNumber(), 'handleOperation'); DriveAutomateResult errorResult = new DriveAutomateResult(); errorResult.folderName = 'Error: ' + e.getMessage(); results.add(errorResult); } finally { FME_Logger.saveLog(); } return results; } global class DriveAutomateResult { @InvocableVariable(description='Id of the folder that is created.') global String folderId; @InvocableVariable(description='Name of the folder that is created.') global String folderName; @InvocableVariable(description='cloud service of the folder.') global String storageType; @InvocableVariable(description='where the folder is stored.') global String driveId; @InvocableVariable(description='Id of the salesforce record.') global String recordId; } }