+ Start a Discussion
NandhuNandhu 

my program is correct trigger for picklist field?

trigger LeaveTrigger on Leaves__c (before insert,before update) {
  LeaveTriggerHandler objHandler = new LeaveTriggerHandler();

  if(trigger.isBefore){
    if(trigger.isInsert){
      objHandler.beforeInsert(trigger.New);
    }
    else if (trigger.isUpdate){
      objHandler.beforeUpdate(trigger.New);
    }                                                                                                                                                            
  } 
}
handler class:
public  with sharing class LeaveTriggerHandler {
    public void beforeInsert(List<Leaves__c> leaveList){ 
         validateLeave(leaveList);
     }
    public void beforeUpdate(List<Leaves__c> leaveList){
         validateLeave(leaveList);
    }
    public void validateLeave(List<Leaves__c> leaveList){
         Map<Id,Leaves__c> mapCase = new Map<Id,Leaves__c>();
         mapCase=new Map<Id,Leaves__c>([SELECT Id,Name,Approval_Status__c FROM Leaves__c]);
       
        for(Leaves__c obj:leaveList){
           if(Approval_Status__c=='Approved'){
              Total_Available_Leaves__c = Total_Available_Leaves__c - Req_Days_Off__c;
            }
            leaveList.add(obj);
        }
    }
}    
NandhuNandhu
i need a picklist value on approval status ==Approved and calculate the formula using trigger.