/*********************************************************************************************************** * Prime * Name : SegmentationBatchProcess * Created By : [Gopi, Viswanath, Venkat] - Prime * Purpose : Controller for uploading approval email for the export * Created Date : 26 Jun 2019 * * Date Modified Modified By Description of the update ---------------------------------------------------------------------------------------------------------- ************************************************************************************************************/ public class ExportUploadController { public Export__c exp { get; set; } public String exportId { get; set; } public Attachment uploadFile { get { if (uploadFile == null) uploadFile = new Attachment(); return uploadFile; } set; } /*constructor to get the export id*/ public ExportUploadController(ApexPages.StandardController controller) { exportId = ApexPages.currentPage().getParameters().get('id'); } public pagereference save() { try { if (uploadFile.body != null) { /*create export upload record*/ Export_Upload__c expupload = new Export_Upload__c(); expupload.Export_Id__c = exportId; expupload.Attachment_Name__c = uploadFile.name; insert expupload; /*create attachment under export upload record*/ Attachment att = new Attachment( parentid = expupload.id, Name = uploadFile.name, Body = uploadFile.body ); insert att; /*update Is_Approval_Email_Uploaded__c field*/ Export__c exp = [SELECT id, Is_Approval_Email_Uploaded__c, Is_Ready_To_Download__c, Status__c FROM Export__c WHERE id = :exportId]; exp.Is_Approval_Email_Uploaded__c = true; if (exp.Is_Ready_To_Download__c) { exp.Status__c = ExportTrackerHelper.READY_TO_DOWNLOAD_STAGE; } else { exp.Status__c = ExportTrackerHelper.EXPORTING_DATA_STAGE; } update exp; /*redirect to the export detail paage after upload*/ PageReference pageRef = new PageReference('/' + exportId); return pageRef; } else { Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.ERROR, 'Please attach approval document.') ); return null; } } catch (Exception e) { SMELogger.logError(e); Apexpages.addMessage( new Apexpages.Message(Apexpages.Severity.INFO, 'An error has occured, please try again.') ); return null; } } }