+ Start a Discussion
prabhakar r 3prabhakar r 3 

TestCode for Trigger Code on this program


trigger posJobAppUpdate2 on Position__c(before update, before insert) {     
  if(className.firstTimeFlag == true) {     List<Job_Application__c> jobAppList = new List<Job_Application__c>();  
  if(Trigger.isUpdate)        jobAppList = [SELECT Id, position__c, status__c, stage__c FROM      Job_Application__c WHERE position__c IN :trigger.newMap.keySet()];     for(Position__c posRec : Trigger.new) {     
if(trigger.isUpdate) {     
    Position__c  oldPosRec = system.trigger.oldMap.get(posRec.Id);   
      if(oldPosRec.status__c == 'Open' && posRec.status__c == 'Closed') {         
    if(jobAppList != NULL && !jobAppList.isEmpty()) {            
     for(Job_Application__c jobApp: jobAppList) {              
       if(jobApp.position__c == posRec.Id) {                         jobApp.Status__c = 'Closed';                         jobApp.stage__c = 'Closed – Position Closed';            
         }       
             }
      
      }      
   }    
   }
}   
   system.debug('jobAppRecList after for loop--->' + jobAppList);     update jobAppList;          className.firstTimeFlag= false;     }      }
 
Best Answer chosen by prabhakar r 3
Vishnu VaishnavVishnu Vaishnav
Hi 

Here is your test class::

@isTest
public class posJobAppUpdate2Test{
    public static testMethod void unitTest() {
        Position__c posObj = new Position__c();
        //REQUIRE FIELDS 
        posObj.status__c = 'Open';
        insert posObj;
        
        Job_Application__c JAObj = new Job_Application__c();
        //REQUIRE FIELDS 
        JAObj.Position__c = posObj.id;
        insert JAObj;
        
        posObj.status__c = 'Closed';
        update posObj;
    }
}

Note : Put the required fields values for Position__c  and Job_Application__c 

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....