+ Start a Discussion
sfdc@isha.ax1814sfdc@isha.ax1814 

Can you please help me out test class for apex class?

Hi Team,

Can you pleae help me out test class for below class which is calling in case trigger before trigger.

Please help me out on this?

public class AH_HN_Stage_Validations {
    public static void validateStatus(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'You are not allowed to skip a stage. Please follow the workflow.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId){
                //Status validation for - QC1
                If(eachCurrentCase.Status == 'QC1'){
                    If(eachCurrentCase.Status == 'QC1' && oldCase.Status=='MRP'){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - Physician Expert Review
                If(eachCurrentCase.Status == 'Physician Expert Review'){
                    If(eachCurrentCase.Status == 'Physician Expert Review' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - QC2
                If(eachCurrentCase.Status == 'QC2'){
                    If(eachCurrentCase.Status == 'QC2' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - AH MD Review
                If(eachCurrentCase.Status == 'AH MD Review'){
                    If(eachCurrentCase.Status == 'AH MD Review' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - Report Sent
                If(eachCurrentCase.Status == 'Report Sent'){
                    If(eachCurrentCase.Status == 'Report Sent' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review' || oldCase.Status=='QC2')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - Peer Consult
                    If(eachCurrentCase.Status == 'Peer Consult  '){
                        If(eachCurrentCase.Status == 'Peer Consult' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review' || oldCase.Status=='QC2' || oldCase.Status=='AH MD Review')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - QC3
                If(eachCurrentCase.Status == 'QC3'){
                    If(eachCurrentCase.Status == 'QC3' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review' || oldCase.Status=='QC2' || oldCase.Status=='AH MD Review' || oldCase.Status=='Report Sent')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - Peer Consult Review Sent
                If(eachCurrentCase.Status == 'Peer Consult Review Sent'){
                    If(eachCurrentCase.Status == 'Peer Consult Review Sent' && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review' || oldCase.Status=='QC2' || oldCase.Status=='AH MD Review' || oldCase.Status=='Report Sent' || oldCase.Status=='Peer Consult')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
                //Status validation for - Closed
                If(eachCurrentCase.Status == 'Closed' && oldCase.Status!='Peer Consult'){
                     If(eachCurrentCase.Status == 'Closed' &&  eachCurrentCase.Close_Reason__c==null && (oldCase.Status=='MRP' || oldCase.Status=='Narrative' || oldCase.Status=='QC1' || oldCase.Status=='Physician Expert Review' || oldCase.Status=='QC2' || oldCase.Status=='AH MD Review' || oldCase.Status=='Report Sent' || oldCase.Status=='QC3')){
                        eachCurrentCase.addError(skipErrorMessage);
                    }                                
                }
            }
        }
    }
    
    //MRP_MR_Review_Validations
    public static void MRPvalidate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please complete MR Review.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            
            Id guestRecordtypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('AH MR Review').getRecordTypeId();
            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'Narrative' && [select Id, Status,(select id from Tasks Where RecordTypeId =:guestRecordtypeId) from Case Where Id =: eachCurrentCase.Id].Tasks.size()==0){
                    eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }
    //Narrative_Fields_Vaidations
    public static void narrativeValidate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please fill clinical Narration.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'QC1' && (eachCurrentCase.Clinical_Narrative__c == null && eachCurrentCase.Clinical_Summary__c == null)){
                    eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }
//Qc1 Fields_Vaidations
    public static void QC1validate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please complete QC1 related task';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            //Id guestRecordtypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('AH Qualitycheck').getRecordTypeId();
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'Physician Expert Review' && [select Id, Status,(select id,status,Activity_Type__c from Tasks Where status='Open' and Activity_Type__c='QC1') from Case Where Id =: eachCurrentCase.Id].Tasks.size()>0){
                    eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }


    //Physician Review Fields_Vaidations
    public static void PhysicianexpertValidate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please update the Physician clinical Review.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            Id PhyRewRecTypeId = Schema.SObjectType.Physician_Review__c.getRecordTypeInfosByName().get('Clinical Review').getRecordTypeId();
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
            if(eachCurrentCase.status=='QC2' && [select Id, Status,(select id, Name from  Physician_Reviews__r Where RecordTypeId =:PhyRewRecTypeId) from Case Where Id =:eachCurrentCase.Id].Physician_Reviews__r.size()==0){
                    //Case varActualCaseRecord2 = (Case)Trigger.newMap.get(vCase1.Id); 
                    eachCurrentCase.adderror(skipErrorMessage );
                }
                  
            }
        }
    }
   //QC2 Validations   
     public static void QC2validate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please complete QC2 related task';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'AH MD Review' && [select Id, Status,(select id from Tasks Where status='Open'and Activity_Type__c='QC2') from Case Where Id =: eachCurrentCase.Id].Tasks.size()>0){
                    eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }
    
    //AH MD Review Validations    
     public static void AHMDReviewvalidate(List<Case> vListCase){
        /*for(Case eachCurrentCase : vListCase){
             String skipErrorMessage = 'Please complete AH MD review related task';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'Report Sent' && [select Id, Status,(select id from Tasks Where status='Completed' and Activity_Type__c='MD Review') from Case Where Id =: eachCurrentCase.Id].Tasks.size()==0){
                    eachCurrentCase.addError(skipErrorMessage);               
                }   
            }
        }*/
    }

    //Peer consult Validations 
   public static void Peerconsultvalidate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){         
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();            
            If((eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId)&& eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'Peer Consult'){                   
                   /* If(eachCurrentCase.Peer_Consult_Required__c=='Yes'){
                       eachCurrentCase.Status = 'QC3';
                    }*/
                    
                    If(eachCurrentCase.Peer_Consult_Required__c=='No'){
                        eachCurrentCase.Status = 'Closed';
                        eachCurrentCase.Sub_Status__c='Completed';
                        //Closedvalidation(vListCase);
                    }      
             }
        }
      }      
    } 
    
     //Peerconsult Validations   
     public static void Peerconsultvalidations(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please update the Physician P2P Review.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            Id PhyRewRecTypeId = Schema.SObjectType.Physician_Review__c.getRecordTypeInfosByName().get('P2P Review').getRecordTypeId();
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'QC3' && [select Id, Status,(select id, Name from  Physician_Reviews__r Where RecordTypeId =:PhyRewRecTypeId) from Case Where Id =:eachCurrentCase.Id].Physician_Reviews__r.size()==0){
                eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }

    //QC3 Validations
     public static void QC3validate(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Please complete QC3 related task';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();
            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
                If(eachCurrentCase.Status == 'Peer Consult Review Sent' && [select Id, Status,(select id from Tasks Where status='Open' and Activity_Type__c='QC3') from Case Where Id =: eachCurrentCase.Id].Tasks.size()>0){
                    eachCurrentCase.addError(skipErrorMessage);               
                }    
            }
        }
    }
    
    //Closed Validations    
     public static void Closedvalidation(List<Case> vListCase){
        for(Case eachCurrentCase : vListCase){
            String skipErrorMessage = 'Outcome must be completed in order to close case.';
            Case oldCase = (Case)Trigger.oldMap.get(eachCurrentCase.Id);
            Id recordtypeAPOId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('APO').getRecordTypeId();
            Id recordtypeEARId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('EAR').getRecordTypeId();            
            If(eachCurrentCase.RecordTypeId == recordtypeAPOId || eachCurrentCase.RecordTypeId == recordtypeEARId && eachCurrentCase.status != oldCase.status){
               if(eachCurrentCase.Status=='Closed'){
                       eachCurrentCase.Sub_Status__c='Completed';
                    If(eachCurrentCase.Sub_Status__c =='Completed' &&  (eachCurrentCase.Humanistic_Outcomes__c==null || eachCurrentCase.Appropriate_Use_of_Healthcare__c==null || eachCurrentCase.Area_of_Cost_Savings__c==null || eachCurrentCase.Outcome_of_Review__c==null)){
                        eachCurrentCase.adderror(skipErrorMessage);
                    } 
               }
            }
        }
    }
}

Regards,
Isha
Abhishek BansalAbhishek Bansal
Hi Isha,

What issue you are facing in writing the test class? It is not possible to write test class just by looking at the code.
You can also contact me on:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Mobile: 7357512102.

Thanks,
Abhishek Bansal.