You need to sign in to do that
Don't have an account?
Pete Watson 5
TestClass Error ( Required fields are missing: [Name, Body]: [Name, Body]) on Visualforce Attachment Upload Controller Extension
Hi all,
I have 82% coverage on the below test class but receiving an error on line 133 of the test class:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name, Body]: [Name, Body]
When I debug the run the name and body fields both apear to have values, not sure where im going wrong?
Any help would be greatly appreciated. Many thanks in advance
I have 82% coverage on the below test class but receiving an error on line 133 of the test class:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name, Body]: [Name, Body]
When I debug the run the name and body fields both apear to have values, not sure where im going wrong?
Any help would be greatly appreciated. Many thanks in advance
@isTest public class ContractUploadTest { @isTest static void ContractUploadTest(){ //Record Types Id RetailRecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Retail').getRecordTypeId(); Id RetailSubAccountRecordType = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Retail Sub-Account').getRecordTypeId(); //Insert Retailer Account Account acc = new Account(Name = 'TestRetailer', Known_As__C = null, RecordTypeID = RetailRecordType, company_Number__c = '00699', company_Reg_No__c = '12345678', Phone = '015165321833', type = 'Customer', website = 'www.new.com', BillingCity = 'City', BillingCountry = 'Country', BillingPostalCode = 'CH41 7ED', BillingStreet = 'Street', Corp_Business_Type__c = 'Staff Rewards- Corporate', Discount__c = '0%', Industry = 'Retail', VAT_Number__c = '000111222', Retailer_Only_Account__c = true, Immediate_Set_Up__c = true, Retail_Sector__c = 'Fashion', Lead_Source__c= 'Networking', Payment_Terms__c = '30days', Service_Fee__c = 10, Credit_Limit__c = string.valueof(10000), Sort_Code__c = '112233', Bank_Account_Number__c = '11223344', VAT_Email__c = 'test@test.com', Remittance_Email__c = 'test@test.com', Day_Working_Week_Ends__c = 'Sunday', Required_Schemes__c = '12', Approx_Redemption_s_Per_Month__c = 1000, Opportunity_Won__c = true, Sub_Account_Type__c = null, Account_Stage__c = 'Active', Partner_Status__c = 'Active', ActiveInactive_Retailer__c = false); checkRecursive.resetRunOnceFlag(); insert acc; System.assert(acc.Id !=null); system.debug('acc inserted: ' +acc.Name); //Create Contact Contact c1 = new Contact(FirstName = 'Peter', LastName = 'LastName', AccountID = acc.id, email = 'test@new.com', Phone = '01516531833'); insert c1; System.assert(c1.Id !=null); acc.Primary_Contact__c = c1.id; acc.Financial_Contact__c = c1.id; update acc; //Create Child Account Account childAcc1 = new Account(Name = acc.Name, Known_As__c = acc.Name +': Voucher Sub-Account', RecordTypeID = RetailSubAccountRecordType, ParentId = acc.id, company_Number__c = '00699', company_Reg_No__c = acc.company_Reg_No__c, Phone = acc.Phone, type = 'Customer', website = acc.website, BillingCity = acc.BillingCity, BillingCountry = acc.BillingCountry, BillingPostalCode = acc.BillingPostalCode, BillingStreet = acc.BillingStreet, Corp_Business_Type__c = 'Staff Rewards- Corporate', Discount__c = '0%', Industry = 'Retail', Retail_Sector__c = acc.Retail_Sector__c, Lead_Source__c= acc.Lead_Source__c, VAT_Number__c = acc.VAT_Number__c, Financial_Contact__c = acc.Financial_Contact__c, Primary_Contact__c = acc.Primary_Contact__c, Payment_Terms__c = acc.Please_confirm_payment_terms__c, Service_Fee__c = acc.Please_confirm_service_fee__c, Credit_Limit__c = string.valueof(acc.Credit_Limit_Required__c), Retailer_Only_Account__c = true, Immediate_Set_Up__c = true, Sort_Code__c = acc.Sort_Code__c, Bank_Account_Number__c = acc.Bank_Account_Number__c, VAT_Email__c = acc.VAT_Email__c, Remittance_Email__c = acc.Remittance_Email__c, Day_Working_Week_Ends__c = acc.Day_Working_Week_Ends__c, Required_Schemes__c = acc.Required_Schemes__c, MerchantID_s__c = acc.MerchantID_s__c, Sub_Account_Type__c = 'Voucher', Approx_Redemption_s_Per_Month__c = acc.Approx_Redemption_s_Per_Month__c, Partner_Status__c = acc.Partner_Status__c); insert childAcc1; System.assert(childAcc1.Id !=null); //Create Contract Record Contract__c c = new Contract__c(Name = 'test', Service_Fee__c = 10, Type_Of_Contract__c = 'Voucher', Contract_Term__c = 'fixed', Start_Date__c = system.today(), Retailer__c = acc.id, Invoicing_Account__c = childAcc1.id); insert c; System.assert(c.Id !=null); ApexPages.currentPage().getParameters().put('id', c.Id); ApexPages.StandardController Contract = new ApexPages.StandardController(c); attachmentUpload controller = new attachmentUpload(Contract); Test.startTest(); Attachment attach = new Attachment(); attach.Name='Unit Test Attachment'; Blob bodyBlob =Blob.valueOf('Unit Test Attachment Body'); attach.body = bodyBlob; attach.parentId = c.id; insert attach; system.debug('******attachment: ' +attach); controller.getmyfile(); controller.Savedoc(); Test.stopTest(); List<Attachment> attachments = [SELECT ID, Name FROM Attachment WHERE parent.id= :c.id]; System.assertEquals(1, attachments.size()); } }
controller.getmyfile();
controller.myfile.parentId = attach.parentId;
controller.myfile.Name = attach.name;
controller.myfile.body = attach.body;
controller.Savedoc();
All Answers
Can you highlight what is line 133 in the above code?Thanks
Appologies - its this line:
controller.Savedoc();
Many thanks
controller.getmyfile();
controller.myfile.parentId = attach.parentId;
controller.myfile.Name = attach.name;
controller.myfile.body = attach.body;
controller.Savedoc();