You need to sign in to do that
Don't have an account?
Sebastian Jud
I need to improve my code coverage
Hi everyone! I need to improve my code coverage, the current code coverage 62%. In my understanding the problem reside in Adobe Docusign. If I am right, is there any way to skip that?
this is the code:
public class UploadAttachmentControllerAccounts { public String selectedType {get;set;} public String description {get;set;} private Account account {get;set;} public String fileName {get;set;} public Blob fileBody {get;set;} public UploadAttachmentControllerAccounts(ApexPages.StandardController controller) { this.Account = (account)controller.getRecord(); } // creates a new Account_Attachment__c record private Database.SaveResult saveCustomAttachment() { Account_Document_Attachment__c obj = new Account_Document_Attachment__c(); obj.Account__c = Account.Id; obj.description__c = description; obj.type__c = selectedType; // fill out cust obj fields return Database.insert(obj); } // create an actual Attachment record with the Account_Attachment__c as parent private Database.SaveResult saveStandardAttachment(Id parentId) { Database.SaveResult result; Attachment attachment = new Attachment(); attachment.body = this.fileBody; attachment.name = this.fileName; attachment.parentId = parentId; // inser the attahcment result = Database.insert(attachment); // reset the file for the view state fileBody = Blob.valueOf(' '); return result; } /** * Upload process is: * 1. Insert new Account_Attachment__c record * 2. Insert new Attachment with the new Account_Attachment__c record as parent * 3. Update the Account_Attachment__c record with the ID of the new Attachment **/ public PageReference processUpload() { try { Database.SaveResult customAttachmentResult = saveCustomAttachment(); if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) { ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Could not save attachment.')); return null; } Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId()); if (attachmentResult == null || !attachmentResult.isSuccess()) { ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Could not save attachment.')); return null; } else { // update the custom attachment record with some attachment info Account_Document_Attachment__c customAttachment = [select id from Account_Document_Attachment__c where id = :customAttachmentResult.getId()]; customAttachment.name = this.fileName; customAttachment.Attachment__c = attachmentResult.getId(); update customAttachment; } } catch (Exception e) { ApexPages.AddMessages(e); return null; } return new PageReference('/'+Account.Id); } public PageReference back() { return new PageReference('/'+Account.Id); } }Test:
Thanks in advance!
All Answers
Thank you Raj! I am having this error now when I am tryng to deploy the change set
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name, Body]: [Name, Body]
Stack Trace: Class.UploadAttachmentControllerAccounts.saveStandardAttachment: line 32, column 1 Class.UploadAttachmentControllerAccounts_Test.testCase1: line 16, column 1
Any ideas?
Thanks again!