I have the following trigger
trigger caseTrigger on Case (before insert, before update) {
if(Trigger.isInsert && Trigger.isUpdate){
UpdateFieldsForApproval updateEmailField = new UpdateFieldsForApproval();
updateEmailField.updateEmailOnCase(trigger.new);
}
and I have the following apex class
public class UpdateFieldsForApproval{
public void updateEmailOnCase(List<Case> newCases){
List<ID> contractorIds = new List<ID>();
for(Case obj : newCases)
{
contractorIds.add(obj.Vendor__c);
}
Map<ID, Vendor__c> caseContractorMap = new Map<ID, Vendor__c>([select Email__c from Vendor__c where ID in :contractorIds]);
for (Case obj : newCases)
{
if (obj.Vendor__c != null)
{
obj.Email_Contractor__c = caseContractorMap.get(obj.Vendor__c).Email__c;
System.debug('In Class--------'+obj.Email_Contractor__c);
}
}
}
}
The Email field of the case which I am trying to update is not getting updated. As far as I know I do not have to use a DML operation for the before trigger. Can anyone tell me where am I going wrong? I am fairly new in Salesforce and any help would be appreciated.