Backup_FME_personal/force-app/main/default/classes/CreateFolderInvocableHandle...

109 lines
4.1 KiB
OpenEdge ABL

global class CreateFolderInvocableHandler {
global static Map<String,String> staticMapForUseInNextTxn = new Map<String,String>();
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<DriveAutomateResult> handleOperation(List<DriveAutomateRequest> request) {
List<DriveAutomateResult> results = new List<DriveAutomateResult>();
try {
String newAccessTokenGnt;
DriveAutomateResult result = new DriveAutomateResult();
Map<String, String> returnmap = new Map<String, String>();
System.debug('apex class ' + JSON.serializePretty(request));
if (request != null && !request.isEmpty()) {
returnmap = (Map<String, String>) 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;
}
}