You need to sign in to do that
Don't have an account?
Scott Janis 6
I need help with a simple trigger in which I can't seem to get coverage for.
This is the trigger :
Trigger CreatingAutoRecords on OrderItem(After Insert, After Update)
{
List<Screens__c> ScreensRecordsFinalListToInsert = New List<Screens__c>();
If(Trigger.IsInsert || Trigger.IsUpdate)
{
For(OrderItem con : Trigger.New)
{
If(con.Quantity != null)
{
List<Screens__c> fetchingAlreadyExixtsedRecords = [Select Id FROM Screens__c WHERE Order_Product__c =:con.Id];
If(fetchingAlreadyExixtsedRecords.IsEmpty())
{
// We are only creating a records when there is no Screen Record records exixts.
For(Integer I = 0; I < con.Quantity; I++)
{
Screens__c crd = New Screens__c();
crd.Order_Product__c = con.Id;
crd.Name = 'Screen';
crd.Account__c = con.Account__c;
ScreensRecordsFinalListToInsert.add(crd);
}
}
}
try{
If(!ScreensRecordsFinalListToInsert.IsEmpty()){
insert ScreensRecordsFinalListToInsert;
}
}
Catch(Exception e){
System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
}
}
}
}
This is the test class:
@isTest
private class CreateAutoRecordsTest {
@istest
private static void insertRecord()
{
List<Screens__c> ScreensRecordsFinalListToInsert = New List<Screens__c>();
Screens__c crd = New Screens__c();
crd.Name = 'Screen';
ScreensRecordsFinalListToInsert.add(crd);
insert ScreensRecordsFinalListToInsert;
}
}
I deploy them together. Then I run try to validate in production and I keep getting a code coverage error.
Trigger CreatingAutoRecords on OrderItem(After Insert, After Update)
{
List<Screens__c> ScreensRecordsFinalListToInsert = New List<Screens__c>();
If(Trigger.IsInsert || Trigger.IsUpdate)
{
For(OrderItem con : Trigger.New)
{
If(con.Quantity != null)
{
List<Screens__c> fetchingAlreadyExixtsedRecords = [Select Id FROM Screens__c WHERE Order_Product__c =:con.Id];
If(fetchingAlreadyExixtsedRecords.IsEmpty())
{
// We are only creating a records when there is no Screen Record records exixts.
For(Integer I = 0; I < con.Quantity; I++)
{
Screens__c crd = New Screens__c();
crd.Order_Product__c = con.Id;
crd.Name = 'Screen';
crd.Account__c = con.Account__c;
ScreensRecordsFinalListToInsert.add(crd);
}
}
}
try{
If(!ScreensRecordsFinalListToInsert.IsEmpty()){
insert ScreensRecordsFinalListToInsert;
}
}
Catch(Exception e){
System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
}
}
}
}
This is the test class:
@isTest
private class CreateAutoRecordsTest {
@istest
private static void insertRecord()
{
List<Screens__c> ScreensRecordsFinalListToInsert = New List<Screens__c>();
Screens__c crd = New Screens__c();
crd.Name = 'Screen';
ScreensRecordsFinalListToInsert.add(crd);
insert ScreensRecordsFinalListToInsert;
}
}
I deploy them together. Then I run try to validate in production and I keep getting a code coverage error.
Please use the following test class:
Please mark my answer as best if it does solves your problem.
All Answers
Please use the following test class:
Please mark my answer as best if it does solves your problem.