function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShunnShunn 

Your organization's code coverage is 4%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

Hi All,

I am not a developer at all and tried to deploy a small apex class from Sandbox to Production and hit this error below. Any help and/or guidance is highly appreciated
Screenshot of Error

Thank You
Best Answer chosen by Shunn
Tanner RussellTanner Russell
this issue seems like it is occuring beacuse Financial_Year_End__c was made requred on the account object a quick fix is to make it not required but if not we can fix this issue by just adding Financial_year_end__c = Date.newInstance(2016, 1, 1) to account inserts

All Answers

Tanner RussellTanner Russell
Looks like you dont have the field Financial Year End in your production org. Do you have this in your sandbox?
ShunnShunn
@Tanner Russel, I have the field on both instances
Tanner RussellTanner Russell
Okay sorry its hard to read the font on the image since its small I am pretty sure it is just saying that the code was trying to modify the financial year field but it was not added in the query example select id, name from account vs select id, name , Financial_Year__c from account you may need a code update
ShunnShunn
Hi Tanner, you are right it wants to modify the financial year end field ; 

TestQuoteDetailstestQuoteDetailsSystem.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Financial_Year_End__c]: [Financial_Year_End__c] 
Stack Trace: Class.TestQuoteDetails.testQuoteDetails: line 21, column 1

TestSuitetestRollupToMasterAccountSystem.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Financial_Year_End__c]: [Financial_Year_End__c] 
Stack Trace: Class.TestSuite.testRollupToMasterAccount: line 13, column 1

TestSuitetestSetQuoteLineItemFieldsSystem.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Financial_Year_End__c]: [Financial_Year_End__c] 
Stack Trace: Class.TestSuite.testSetQuoteLineItemFields: line 50, column 1

UtilitiestestSetQuoteLineItemFieldsSystem.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Financial_Year_End__c]: [Financial_Year_End__c] 
Stack Trace: Class.Utilities.testSetQuoteLineItemFields: line 117, column 1

I wouldn't even know how to modify the code. Shall I paste the code here?
Tanner RussellTanner Russell
yeah sure if you paste it i can try to help
ShunnShunn
Hi Tanner, thanks for this. We can start with one of the classes for now and then maybe I can walk through the rest?

For the TestQuoteDetails see below:

@isTest
public class TestQuoteDetails {
    static testMethod void testQuoteDetails() {

        CustSettings__c custSettings = new CustSettings__c(Hardware_LTD_Maintenance_Product_Code__c='MTCE-H/W-PRE-001',
                                                           Hardware_Maintenance_Product_Code__c='MTCE-H/W-004',
                                                           Hardware_STD_Maintenance_Product_Code__c='MTCE-H/W-STD-001',
                                                           Software_LTD_Maintenance_Product_Code__c='MTCE-S/W-PRE-001',
                                                           Software_Maintenance_Product_Code__c='MTCE-S/W-005',
                                                           Software_STD_Maintenance_Product_Code__c='MTCE-S/W-STD-001'
                                                          );
        insert custSettings;
        
        Product2 p = new Product2(Name = 'Sample Product',ProductCode = 'SUPXXXXXXXXX',Family='Appliance',IsActive = true);
        insert p;
        
        PriceBookEntry pbe = new PriceBookEntry(Product2Id = p.Id,UnitPrice = 200,IsActive = true,Pricebook2Id = Test.getStandardPricebookId());
        insert pbe;
        
        Account a = new Account(Name='acc1');
        insert a;
        
        Opportunity op = new Opportunity(AccountId=a.Id, Name='opp1', CloseDate=System.today(), StageName='Prospect - (0CSFs)', Pricebook2Id=pbe.Pricebook2Id);
        insert op;
        
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=op.Id,Quantity=1,PriceBookEntryId=pbe.Id,UnitPrice=200);
        insert oli;
        
        Quote q = new Quote(OpportunityId=op.Id,Name='quote1',PriceBook2Id=pbe.Pricebook2Id,Shipping_Terms__c='ship');
        insert q;
        
        QuoteLineItem qli = new QuoteLineItem(QuoteId=q.Id,Quantity=1,PriceBookEntryId=pbe.Id,UnitPrice=200);
        insert qli;
        
        QuoteDetails controller = new Quotedetails();
        controller.relatedTo = q;
        List<QuoteLineItem> qlis = controller.getQuoteLineItems;
    }
}

Thanks
Tanner RussellTanner Russell
What object is the Financial Year field on?
ShunnShunn
on the account object
Tanner RussellTanner Russell
okay i think i see the issue its on the insert account line what is an example Finacial year? what is the data type is it a date? just want to make sure
Tanner RussellTanner Russell
if its a date try 
@isTest
public class TestQuoteDetails {
    static testMethod void testQuoteDetails() {

        CustSettings__c custSettings = new CustSettings__c(Hardware_LTD_Maintenance_Product_Code__c='MTCE-H/W-PRE-001',
                                                           Hardware_Maintenance_Product_Code__c='MTCE-H/W-004',
                                                           Hardware_STD_Maintenance_Product_Code__c='MTCE-H/W-STD-001',
                                                           Software_LTD_Maintenance_Product_Code__c='MTCE-S/W-PRE-001',
                                                           Software_Maintenance_Product_Code__c='MTCE-S/W-005',
                                                           Software_STD_Maintenance_Product_Code__c='MTCE-S/W-STD-001'
                                                          );
        insert custSettings;
        
        Product2 p = new Product2(Name = 'Sample Product',ProductCode = 'SUPXXXXXXXXX',Family='Appliance',IsActive = true);
        insert p;
        
        PriceBookEntry pbe = new PriceBookEntry(Product2Id = p.Id,UnitPrice = 200,IsActive = true,Pricebook2Id = Test.getStandardPricebookId());
        insert pbe;
        
        Account a = new Account(Name='acc1', Financial_year_end__c = Date.newInstance(2016, 1, 1));
        insert a;
        
        Opportunity op = new Opportunity(AccountId=a.Id, Name='opp1', CloseDate=System.today(), StageName='Prospect - (0CSFs)', Pricebook2Id=pbe.Pricebook2Id);
        insert op;
        
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=op.Id,Quantity=1,PriceBookEntryId=pbe.Id,UnitPrice=200);
        insert oli;
        
        Quote q = new Quote(OpportunityId=op.Id,Name='quote1',PriceBook2Id=pbe.Pricebook2Id,Shipping_Terms__c='ship');
        insert q;
        
        QuoteLineItem qli = new QuoteLineItem(QuoteId=q.Id,Quantity=1,PriceBookEntryId=pbe.Id,UnitPrice=200);
        insert qli;
        
        QuoteDetails controller = new Quotedetails();
        controller.relatedTo = q;
        List<QuoteLineItem> qlis = controller.getQuoteLineItems;
    }
}

 
Tanner RussellTanner Russell
this issue seems like it is occuring beacuse Financial_Year_End__c was made requred on the account object a quick fix is to make it not required but if not we can fix this issue by just adding Financial_year_end__c = Date.newInstance(2016, 1, 1) to account inserts
This was selected as the best answer
ShunnShunn
Ok,Let me try making the field non mandatory and then run the deployment again.
ShunnShunn
I have made the field non-required in both instances but same error. It is a picklist field as well. 
Tanner RussellTanner Russell
Thats very odd concidering the error says that it is a required field. If you go to create a new account can you make it without that field populated? 
ShunnShunn
Tanner, So I am able to create an account without that field populated. 
Tanner RussellTanner Russell
First I would try to re run all the tests, than if that doesnt work we can try making it so the picklist chooses a default value automatically and if that doesnt work we can set the picklist field to a value in the code for each class
ShunnShunn
ok, rerun the tests in sandbox? When I do it fails
 
ShunnShunn
Thanks Tanner! I made the field non-required again and made it required on the pagelayout and it seemed to fix the issue. Thanks for your help!
 
Tanner RussellTanner Russell
Thats great glad we were able to fix this without having to modify any code cheers!