You need to sign in to do that
Don't have an account?
John Neilan
Dataloader Insert Not Firing Trigger
Hello,
I have an after trigger that fires when a task is inserted, updated, deleted, or undeleted. I added a number of tasks via the dataloader and the trigger did not fire. When I went into one of the tasks and just clicked edit/save, the trigger fired. Does anyone know how I can get it to fire when the dataloader is used?
Trigger:
Class:
I have an after trigger that fires when a task is inserted, updated, deleted, or undeleted. I added a number of tasks via the dataloader and the trigger did not fire. When I went into one of the tasks and just clicked edit/save, the trigger fired. Does anyone know how I can get it to fire when the dataloader is used?
Trigger:
trigger MainTriggerTask on Task (after insert, after update, after delete, before delete, after undelete) { IF(Trigger.IsAfter){ IF(Trigger.IsInsert){ ClassRenewalTasks updater6 = new ClassRenewalTasks(); updater6.renewalTasks(Trigger.new); } IF(Trigger.IsUpdate){ ClassRenewalTasks updater3 = new ClassRenewalTasks(); updater3.renewalTasks(Trigger.new); } } ELSE IF(Trigger.IsBefore){ IF(Trigger.IsDelete){ ClassRenewalTasks deleteTsk = new ClassRenewalTasks(); deleteTsk.deleteTasks(Trigger.old); } } }
Class:
public class ClassRenewalTasks { public void deleteTasks(List<Task> delTasks) { List<Opportunity> linkedOpps = new List<Opportunity>(); Map<Id, Task> taskMap = new Map<Id, Task>(); for (Task t: delTasks) { taskMap.put(t.WhatId, t); System.Debug('******** TaskMapDel ' + TaskMap); } if (taskMap.size() > 0) { linkedOpps = [SELECT Id,Account.Id, Effective_Date__c, Renewal_Date_Next__c, RP_User_Training__c, RP_Initial_Program_Developed__c, RP_Recommendation_Review_Call__c FROM Opportunity WHERE Account.Id IN: taskMap.keySet() AND IsClosed =: FALSE]; for (Opportunity opp1: linkedOpps){ for (Task delTask:[SELECT WhatId, Subject, Status, ActivityDate FROM Task WHERE WhatId =: opp1.Account.Id AND Status =: 'Completed' AND ActivityDate >=: opp1.Effective_Date__c AND ActivityDate <=: opp1.Renewal_Date_Next__c]){ IF(delTask.Subject == 'Initial Program Confirmation'){ opp1.RP_Initial_Program_Developed__c = FALSE; } IF(delTask.Subject == 'Renewal Package Review'){ opp1.RP_Recommendation_Review_Call__c = FALSE; } } } } // if the list of cons isnt empty, update them system.debug('linkedOpps = '+linkedOpps); if (linkedOpps.size() > 0) { update linkedOpps; } } public void renewalTasks(List<Task> checkTasks) { // set up lists you will need List<Opportunity> linkedOpps = new List<Opportunity>(); Map<Id, Task> taskMap = new Map<Id, Task>(); // go through the list of tasks that were inserted for (Task t: checkTasks) { // if they are related to a contact, add the contact id (whoID) and their values to a map if (t.WhatId != null && (t.Subject == 'Initial Program Confirmation' || t.Subject == 'Renewal Package Review')){ taskMap.put(t.WhatId, t); } } system.debug('taskMap = '+taskMap); if (taskMap.size() > 0) { // get all of the contacts related to the tasks linkedOpps = [SELECT Account.Id, Effective_Date__c, Renewal_Date_Next__c, RP_User_Training__c, RP_Initial_Program_Developed__c, RP_Recommendation_Review_Call__c FROM Opportunity WHERE Account.Id IN: taskMap.keySet() AND IsClosed =: FALSE]; // go through the list for each contact for (Opportunity c: linkedOpps){ for (Task task2:[SELECT WhatId, Subject, Status, ActivityDate FROM Task WHERE WhatId =: c.Account.Id AND ActivityDate >=: c.Effective_Date__c AND ActivityDate <=: c.Renewal_Date_Next__c]){ IF(task2.Subject == 'Initial Program Confirmation' && task2.Status == 'Completed'){ c.RP_Initial_Program_Developed__c = TRUE; } IF(task2.Subject == 'Renewal Package Review' && task2.Status == 'Completed'){ c.RP_Recommendation_Review_Call__c = TRUE; } IF(task2.Subject == 'Initial Program Confirmation' && task2.Status <> 'Completed'){ c.RP_Initial_Program_Developed__c = FALSE; } IF(task2.Subject == 'Renewal Package Review' && task2.Status <> 'Completed'){ c.RP_Recommendation_Review_Call__c = FALSE; } } } // if the list of cons isnt empty, update them system.debug('linkedOpps = '+linkedOpps); if (linkedOpps.size() > 0) { update linkedOpps; } } } }
All Answers
Trigger will work even if you are inserting the records through Data loader.
Will you please check if the records you inserting are meeeting the trigger execution condition?
Thanks,
Pratik
Thanks,
Pratik