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
udayarangareddy mekalaudayarangareddy mekala 

Trigger Test Class

HI
I got the error in the Trigger Test Class.The error is Selected job is not yet complete in Apex Test Execution.


Thanks&Regards
Ranga

 
Amit Chaudhary 8Amit Chaudhary 8
// Below code Abort all job
                    for (CronTrigger ct : [SELECT Id FROM CronTrigger]) {
                        System.abortJob(ct.Id);
                    }

Please try below code. I hope that will help you
@isTest
private class CustomerPortalRevokeSchedulableTest {

    static testMethod void myUnitTest() {

            Test.startTest();
					
					// Below code Abort all job
					for (CronTrigger ct : [SELECT Id FROM CronTrigger]) {
						System.abortJob(ct.Id);
					}	
				
					// Then try below code to schedule job
                    String CRON_EXP = '0 0 0 1 1 ? 2025';  
                    String jobId = System.schedule('testScheduledApex', CRON_EXP, new CustomerPortalRevokeSchedulable() );

                    CronTrigger ct = [select id, CronExpression, TimesTriggered, NextFireTime from CronTrigger where id = :jobId];

                    System.assertEquals(CRON_EXP, ct.CronExpression); 
                    System.assertEquals(0, ct.TimesTriggered);
                    System.assertEquals('2025-01-01 00:00:00', String.valueOf(ct.NextFireTime));

            Test.stopTest();
    }
}


Please let us know if this will help you
vasu sfdc_21vasu sfdc_21
Hi ,

I want to write below trigger test class. Please help me out not getting 100% code coverage

trigger OpportunityTriggerUpdate on Opportunity (after update) {
     
    Map <Id,  Opportunity> mapOpportunity = new Map < Id, Opportunity >();
    Map <Opportunity, String> Endcustomeracctype = new Map < Opportunity, String >();
    List <Account> accList = new List < Account >();
    List <Account> accountList = new List < Account >();
    Opportunity opp = new Opportunity();
    List <Id> accIdsList = new List <Id>();
 
    
    for ( Opportunity oppty : trigger.new ) {
        
        if(oppty.End_Customer__c != null){
            System.debug('Print End Customer'+oppty.End_Customer__c);
            accIdsList.add(oppty.End_Customer__c);
            System.debug('Print Account..............'+oppty.StageName);
            if(oppty.StageName == 'Contract Signed'){
                System.debug('Print Account..............'+oppty.StageName);
                for(Account acc : [Select Id,Name,Type from Account where ID IN : accIdsList]){
                  System.debug('Print Account.....'+ acc); 
                    
                    
                   // acc.Type = ('Customer','Prospect');
                    if(acc.Type != null && acc.Type !='Partner' && acc.Type !='Competitor' && acc.Type !='Customer'){
                        System.debug('Print Account Type.........'+acc.Type);
                        acc.Type  = 'Indirect Customer';
                        System.debug('Print Account Type.........'+acc.Type);
                        accList.add(acc);
                        System.debug('Print Account Type.........'+accList);                     
                         
                        
                          }
                    }                   
                    
                }
            }
            
        }  
    update accList;
    System.debug('Update Account List...........'+accList);
    }


Thanks !!