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
Ronaldo CostaRonaldo Costa 

Opportunity Trigger Class

Hello all,

Please review the code below, I don't get why its not passing 100%

Trigger:
trigger CreateFlightItinerary on Opportunity (after update) {    
List<Itinerary__c> fi = new List<Itinerary__c>();
    for (Opportunity a: Trigger.New)
         if (a.fi_automation_check__c == TRUE){
                 fi.add (new Itinerary__c(
                     Flight_Booking__c = a.Id,
					 Stop_1__c = a.Stop1_ID__c,
					 Flight_Crew_1__c = a.CrewM_1_ID__c
				));
         }
   insert fi;
}

Test:
 
@isTest
private class testCreateFlightItinerary{
    static TestMethod void myTestClass()
    {
    	Account a = new Account();
	    a.Name = 'TestName';
	    a.Phone = '5512991224391';
        insert a;

    	Opportunity o = new Opportunity();
	    o.Name = 'TestName';
            o.AccountID = a.Id;
            o.closedate = system.today();
            o.stagename = 'Sample Quote';
            o.Aircraft_Type__c = 'King Air';
            o.fi_automation_check__c=True;
        insert o;             
    }
}

I get not coverage on the highlight line "fi.add (new Itinerary__c("


Thankss!!

Ronaldo.
Shailesh DeshpandeShailesh Deshpande
The trigger you have is on after update event whereas in the test class you are inserting the opportunity. Hence it wont cover your trigger. I suggest to make below change:
 
Opportunity o = new Opportunity();
 o.Name = 'TestName';
o.AccountID = a.Id;
o.closedate = system.today();
o.stagename = 'Sample Quote';
o.Aircraft_Type__c = 'King Air';
o.fi_automation_check__c=false; //set initially to false
insert o; 

o.fi_automation_check__c=true; //set  to true and perform update
update o;

 
Ronaldo CostaRonaldo Costa
Hi Shailesh,

It still at 80%, same line uncovered. Any ideas?

Perhaps it is not creating the Itinerary record?

Thanks,

Ronaldo.
Amit Chaudhary 8Amit Chaudhary 8
Please try below test class and let us know if this will help you
@isTest
private class testCreateFlightItinerary{
    static TestMethod void myTestClass()
    {
    	Account a = new Account();
	    a.Name = 'TestName';
	    a.Phone = '5512991224391';
        insert a;

    	Opportunity o = new Opportunity();
	    o.Name = 'TestName';
            o.AccountID = a.Id;
            o.closedate = system.today();
            o.stagename = 'Sample Quote';
            o.Aircraft_Type__c = 'King Air';
            o.fi_automation_check__c=false;
        insert o;             
		
		o.fi_automation_check__c=true; 
		update o;
		
    }
}

Let us know if this will help you

Thanks
Amit Chaudhary