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 

Trigger Opportunity test class @80%

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 Class
 
@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';
        insert o;

        Itinerary__c i = new Itinerary__c();
	    i.Flight_Booking__c = o.Id;
		
        insert i;
        
    }
}

I highlighted the line "fi.add (new Itinerary__c(" which is not passing.

Thanks a lot!

Ronaldo.
ManojjenaManojjena
Hi Ronaldo,
try below code .
@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;

        Itinerary__c i = new Itinerary__c();
	    i.Flight_Booking__c = o.Id;
		
        insert i;
        
    }
}

 
Ronaldo CostaRonaldo Costa
Still at 80% with the same issue, should I query the Itinerary object to assert the results? Do you think that would help?
Ronaldo CostaRonaldo Costa
Tried several other ways, no lucky so far to achieve 100%

 
Ronaldo CostaRonaldo Costa
@bump