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
RejonesRejones 

Apex Code Test Class

I built this code and migrated it to Production at the time it worked fine. Now it is throwing a error message because a new Validation Rule was built after the migration was done.  What do I need to to to fix the Test Class. 

 

Current Test Class

 

@istest
public class TestClassOpportunitySubmitForApproval{

static testMethod void TestMethodApp() {
 
 
   list<id> ids=new list<id>();
  ids.add('00570000001TNMK');
  RecordType rt=[Select r.Id, r.Name, r.SobjectType from RecordType r Where r.Name='Paycard Team' And r.SobjectType='Opportunity' And IsActive=true];
   Opportunity opp=new opportunity(name='test',closeDate=Date.newInstance(2012,7,23), StageName='prospect', Incentive_Offer__c='yes',Incentive_Justification__c='Test',RecordTypeID=rt.id,ForecastCategoryName='pipeline',type='New Business', Product_Category__c='RCS', Opportunity__c='Branded Debit Payroll',
   Adoption_Rate__c=15.0,Total_Employees__c=10,Pay_Cycle__c='Weekly',Current_Employees_Recieving_Checks__c=200,Standard_Pricing__c='Yes',Opportunity_Justification__c='Test');
   insert opp;
       /* Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setNextApproverIds(ids);
        req1.setObjectId(opp.id);
        
        // Submit the approval request for the opportunity
    
        Approval.ProcessResult result = Approval.process(req1);*/
}
        


}

Error Message

 

BUILD FAILED
C:\Users\deepika\Desktop\Comdata\Migration\Prod\build.xml:14: FAILURES:
Test failure, method: TestClassOpportunitySubmitForApproval.TestMethodApp -- Sys
tem.DmlException: Insert failed. First exception on row 0; first error: FIELD_CU
STOM_VALIDATION_EXCEPTION, Please add a value in the Months Active Per Year: [Mo
nths_Active_Per_Year__c] stack Class.TestClassOpportunitySubmitForApproval.TestM
ethodApp: line 12, column 1

Code coverage issue, class: OpportunitySubmitForApproval -- Test coverage of sel
ected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all Apex Classes and Trigger
s is 0%, at least 75% test coverage is required.

liron169liron169

The error tells you what exacly you need to do:

"Please add a value in the Months Active Per Year"

 

Add value in this field before you insert the record.

RejonesRejones

Yes that I get, but we are not inserting a record.  We have a new process that was built in the sandbox that we are trying to move to porduction and we are getting this error message.  (see below) if I deactivate the Validation rule it allows us to move the new data to production. We dont want to have to deactive this validation rule everytime.  This validation rule was originally built and tested with another process that we moved from the Sandbox to Production and at the time it was not an issue.  Now it is causing this error message and I think it is because this field is not in the orginal test class. 

 

 

BUILD FAILED
C:\Users\deepika\Desktop\Comdata\Migration\Prod\build.xml:14: FAILURES:
Test failure, method: TestClassOpportunitySubmitForApproval.TestMethodApp -- Sys
tem.DmlException: Insert failed. First exception on row 0; first error: FIELD_CU
STOM_VALIDATION_EXCEPTION, Please add a value in the Months Active Per Year: [Mo
nths_Active_Per_Year__c] stack Class.TestClassOpportunitySubmitForApproval.TestM
ethodApp: line 12, column 1

Code coverage issue, class: OpportunitySubmitForApproval -- Test coverage of sel
ected Apex Trigger is 0%, at least 1% test coverage is required
Code coverage issue -- Average test coverage across all Apex Classes and Trigger
s is 0%, at least 75% test coverage is required.

liron169liron169
Again, you must update the test class that it won't fail.
Fix the test class and deploy it with the changes you trying to deploy right now.
crop1645crop1645

1 - The Sandbox should have the same validation rules as PROD (that is, if you added a validation rule to prod without also adding it to the sandbox, these issues arise during the deployment)

 

2 - Your test class DOES insert records -- see the line 'insert opps'