You need to sign in to do that
Don't have an account?

Test class deployment error
I have written the following code in sandbox which is showing 100% test coverage .
But during deployment it is showing the following error:
System.AssertException: Assertion Failed: Expected: false, Actual: true
Stack Trace: Class.DeleteBillingItemsTest.DeleteBillingItemsTest: line 37, column 1.
Code is as follows:
public class DeleteBillingItems
{
@InvocableMethod
public static void BIDelete(List<Id> BIIds)
{
List<BillingItem__c> BI =[select id,BillingDocumentId__c,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
where BillingItem__c.id in :BIIds and BillingDocumentId__c!=Null
and UnitPrice__c=0 and Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
delete BI;
}
}
@isTest
Public class DeleteBillingItemsTest{
Static testMethod void DeleteBillingItemsTest(){
Account acc=new Account();
acc.Name='Test';
insert acc;
Product2 Pd1=new Product2();
Pd1.Name='Pd01';
Pd1.Production_Location__c='SMT-TH';
Pd1.SAP_Product_Nr__c='123';
Pd1.Module_Source__c='bought';
insert pd1;
BillingDoc__c BD1=new BillingDoc__c();
BD1.DocumentType__c='Test01';
BD1.Name='001';
BD1.Production_Location__c='SMT-TH';
BD1.DocumentTypeCode__c='ZOR';
BD1.DocumentDate__c=System.Today();
BD1.FacturaDate__c=System.Today();
insert BD1;
BillingItem__c BI= new BillingItem__c();
BI.Name='Test';
BI.Quantity__c=100;
BI.Units__c='PCE';
BI.UnitPrice__c= 500;
BI.Product2__c=PD1.id;
BI.BillingDocumentId__c=BD1.ID;
insert BI;
BI.UnitPrice__c= 0;
Update BI;
BillingItem__c deletedBI = [SELECT Id, IsDeleted FROM BillingItem__c WHERE Id = :BI.Id ALL ROWS];
System.assertEquals(deletedBI.IsDeleted, true);
}
}
But during deployment it is showing the following error:
System.AssertException: Assertion Failed: Expected: false, Actual: true
Stack Trace: Class.DeleteBillingItemsTest.DeleteBillingItemsTest: line 37, column 1.
Code is as follows:
public class DeleteBillingItems
{
@InvocableMethod
public static void BIDelete(List<Id> BIIds)
{
List<BillingItem__c> BI =[select id,BillingDocumentId__c,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
where BillingItem__c.id in :BIIds and BillingDocumentId__c!=Null
and UnitPrice__c=0 and Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
delete BI;
}
}
@isTest
Public class DeleteBillingItemsTest{
Static testMethod void DeleteBillingItemsTest(){
Account acc=new Account();
acc.Name='Test';
insert acc;
Product2 Pd1=new Product2();
Pd1.Name='Pd01';
Pd1.Production_Location__c='SMT-TH';
Pd1.SAP_Product_Nr__c='123';
Pd1.Module_Source__c='bought';
insert pd1;
BillingDoc__c BD1=new BillingDoc__c();
BD1.DocumentType__c='Test01';
BD1.Name='001';
BD1.Production_Location__c='SMT-TH';
BD1.DocumentTypeCode__c='ZOR';
BD1.DocumentDate__c=System.Today();
BD1.FacturaDate__c=System.Today();
insert BD1;
BillingItem__c BI= new BillingItem__c();
BI.Name='Test';
BI.Quantity__c=100;
BI.Units__c='PCE';
BI.UnitPrice__c= 500;
BI.Product2__c=PD1.id;
BI.BillingDocumentId__c=BD1.ID;
insert BI;
BI.UnitPrice__c= 0;
Update BI;
BillingItem__c deletedBI = [SELECT Id, IsDeleted FROM BillingItem__c WHERE Id = :BI.Id ALL ROWS];
System.assertEquals(deletedBI.IsDeleted, true);
}
}
Hi,
If you have automated trigger/automation that deleted the record as soon as you set UnitPrice__c == 0, Make sure you deploy this trigger/code along with your test class deployment.
Regards,
Paras Bhatt
Steven yes thet worked.One more query:
public class DeleteBillingItems
{
@InvocableMethod
public static void BIDelete(List<Id> BIIds)
{
List<BillingItem__c> BI =[select id,BillingDocumentId__c,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
where BillingItem__c.id in :BIIds and BillingDocumentId__c!=Null
and UnitPrice__c=0 and Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
delete BI;
}
}
This code is deleting the Billing item once created with menntioned criteria.But if we are undeleting then in that case also I want to delete the Item.Or we can say I want to permaently delete it
Stack TraceClass.DeleteBillingItems.BIDelete: line 10, column 1
Class.DeleteBillingItemsTest.DeleteBillingItemsTest: line 38, column 1