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
sfdc@isha.ax1814sfdc@isha.ax1814 

test class for trigger on after update- URGENT

Hi ,

Case trigger handler class:

// Batch Class conversion handler    
        if(checkRecursive.opptyLineItemInsertRunOnce()){
            for(case c: (List<Case>)Trigger.new){
                Case oldCase = (Case)Trigger.oldMap.get(c.Id);
                Boolean oldCaseStatus = oldCase.Status.equals('Closed');
                Boolean newCaseStatus = c.Status.equals('Closed');
                if (oldCaseStatus!=newCaseStatus && c.AccountId!=null && c.ContactId!=null) {
SMXProcessCaseFaasATIHandler smxHandler= new SMXProcessCaseFaasATIHandler();
                    smxHandler.convertBatchToTrigger(trigger.new); 
                }
               }

SMXProcessCaseFaasATIHandler my handler class having logic of after update.
My test class is on after update oncase which is not firing .My method is"convertBatchToTrigger".

My test class:
@isTest
public class CaseTriggerHandlerBatchclassTest{
    public static testMethod void testcreatefeedbacksurvey(){
    
    Account acc = new Account(
            Name='testAcc'
        );
    
    insert acc;
    
    Contact con = new Contact(
            firstname='test',Lastname='Con',
            Email='test@gmail.com',
            AccountId=acc.Id,Not_Active_Contact__c=false,HasOptedOutOfEmail=false
        );
    
    insert con;
    
    
    RecordType red= [SELECT Id FROM RecordType WHERE Name ='FaaS Compromise Report' AND SObjectType = 'Case'];
        Case cse = new Case(
            AccountId=acc.Id,ContactId=con.Id,
            RecordTypeId = red.Id,Status='New',Origin = 'Phone'

        );
        Insert cse;
       
        
          OCM_Agent__c ocm= new OCM_Agent__c(CM_Threat_Contact__c= 'Primary',Contact__c=con.Id);
          Insert ocm;
        
        NPX_Survey_record__c npxsurvey= New NPX_Survey_record__c();
         npxsurvey.Contact__c = cse.ContactId ;
                         npxsurvey.Account__c =acc.id;
                         npxsurvey.Case__c = cse.id; 
                        // npxsurvey.Survey_Id__c = strSurveyId;
                         npxsurvey.Status__c = 'Nominated'; 
                         npxsurvey.Survey_name__c= 'FaaS Compromise Survey';
                         npxsurvey.Person_identifier__c=con.Email;
                         npxsurvey.First_Name__c=con.FirstName;
                         npxsurvey.Last_Name__c=con.LastName;
                         npxsurvey.Email__c=con.Email;
                         npxsurvey.Company_Name__c=acc.Name;
                         npxsurvey.Company_ID__c=acc.Id;
                         npxsurvey.Case_Record_Type__c=cse.RecordTypeId;
                         npxsurvey.Locale_Code__c='test';
                         npxsurvey.Contact__c=con.id;
                         Insert npxsurvey;
                         
         cse.Managed_Defense__c='CV';                       
         cse.Status= 'Closed';
         update cse;
  }
 
 }

Which is not working.

Pls help me on this testclass
 
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Please follow the best practices while implementing the test classes to make sure to get the good coverage.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri