You need to sign in to do that
Don't have an account?
NANDHINI k 9
trigger helper program is whether is correct or wrong?
public with sharing class LeaveTriggerHelper {
public static void createTotalLeave(List<Employee_Detail__c> EmpList){
List<Leaves__c> LeaveList = new List<Leaves__c>();
for (Leaves__c obj: EmpList) {
if (obj.Approval_Status__c == 'Approved')
{
// condition to check the old value and new value
Leaves__c objLeave = new Leaves__c(); //To get the total leave value is separating from(EmpList) No.of.available.Leave and LeaveTaken(Leaves)
obj.Total_Leave__c=EmpList.No_of_available_Leave__c - obj.Leave_Taken__c;
LeaveList.add(objLeave);
}
}
insert LeaveList; // DML to insert the Invoice List in SFDC
}
}
public static void createTotalLeave(List<Employee_Detail__c> EmpList){
List<Leaves__c> LeaveList = new List<Leaves__c>();
for (Leaves__c obj: EmpList) {
if (obj.Approval_Status__c == 'Approved')
{
// condition to check the old value and new value
Leaves__c objLeave = new Leaves__c(); //To get the total leave value is separating from(EmpList) No.of.available.Leave and LeaveTaken(Leaves)
obj.Total_Leave__c=EmpList.No_of_available_Leave__c - obj.Leave_Taken__c;
LeaveList.add(objLeave);
}
}
insert LeaveList; // DML to insert the Invoice List in SFDC
}
}
Please find few observations on your handler below,
1. EmpList is of type Employee_Detail__c but in the for loop you're trying to loop through Leaves__c object type.
2. To compare the old and new values we can do like below,
from trigger,
LeaveTriggerHelper.createTotalLeave(Trigger.oldMap, Trigger.newMap)
from class,
Public Class LeaveTriggerHelper {
Public static void createTotalLeave(Map<Id,Employee_Detail__c> OldMap,Map<Id,Employee_Detail__c> NewMap) {
for(Employee_Detail__c empObj:NewMap.keyset()) {
if(Oldmap.get(empObj.Id).name!=Newmap.get(empObj.Id).name) {
//Process records
} } } }
Im not sure about the relationship between Employee_Detail__c and Leaves__c so i couldn't able to modify your trigger.
Please let us know, if this helps.
Thanks,
Govindaraj.S
Please keep this community clean by closing solved cases
Thanks,
Govindaraj.S