function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
B2AB2A 

Trigger won't fire on mass email??

Hi,

 

I've created a trigger which seems to work perfectly fine when sending email from a Lead record manually (as a task).  However, when sending a Mass email to several  leads the trigger fails to fire.  Not sure why this is happening as I thought my code would handle bulk.   I've pasted the code below..

 

trigger UpdateLeadAfterMassEmail on Task (after insert) { /**This is designed to update a date field on a Lead record once 1 week or 2 week follow up email has been mass mailed*/ integer mycounter = 0; string LeadID =''; List<Id> Ids = New List<Id>(); //Stores a batch of tasks For (Task NewRecord : trigger.new){ if(NewRecord.whoid != null){ LeadID = NewRecord.whoid; if(LeadID.startsWith('00Q')){ if(NewRecord.subject.startsWith('Email: Test email 1')){ Ids.add(LeadId); }else if(NewRecord.subject.startsWith('Mass Email: Followup3')){ Ids.add(LeadId); } } } } List<Lead> Lead_list = [Select Id, Second_Notification_Sent__c, Final_Notification_Sent__c FROM Lead Where Id IN: Ids]; For (Task NewRecord: trigger.new){ if(LeadID.startsWith('00Q')){ if(NewRecord.subject.startsWith('Email: Test email 1')){ Lead_list[mycounter].Second_Notification_Sent__c = date.today(); } else if(NewRecord.subject.startsWith('Mass Email: Followup3')){ Lead_list[mycounter].Final_Notification_Sent__c = date.today(); } } mycounter++; } update(Lead_list); }

 

Best Answer chosen by Admin (Salesforce Developers) 
B2AB2A

Yes, it would require a manual click but far more faster.  Also, I just realized that you can just mass update records from a list view by selected which ever record(s) (or select all) and do inline editting and choose to apply the field update to all selected records!

 

 

All Answers

Cool_DevloperCool_Devloper

Did you check the debug logs, what's happening? Are you able to see task created against each of the lead you selected?

Code seems fine to me!

Cool_D

Message Edited by Cool_Devloper on 12-03-2009 04:44 AM
B2AB2A

Hey Cool,

 

When I view debug log after I create a simple email task i see the insert into the DB and it references the "update" in my code.  But when I send a mass email  out nothing shows on the debug log at all unless i'm doing something wrong?

B2AB2A

I found this from the developer guide:

 

Operations That Do Not Invoke Triggers

Triggers are only invoked for data manipulation language (DML) operations that are initiated or processed by the Java

application server. Consequently, some system bulk operations do not currently invoke triggers. Some examples include:

Cascading delete operations. Records that did not initiate a delete do not cause trigger evaluation.

Cascading updates of child records that are reparented as a result of a merge operation

Mass campaign status changes

Mass division transfers

Mass address updates

Mass approval request transfers

Mass email actions

Modifying custom field data types

Renaming or replacing picklists

Managing price books

Note: Inserts, updates, and deletes on person accounts fire account triggers, not contact triggers.

 

 

DOES this mean I cannot do this at all?  Any workarounds that anyone can think of?

Cool_DevloperCool_Devloper

I am afraid, it might not be possible:(

Only if you could tweak the mass email process, would there have been a way out but I am not sure if that's possible either!

Cool_D

B2AB2A

AHHHHHHHHHHHHHHHHHHHHHHHHH!! :(

 

Hmm.. how about the idea of creating a mass update button that goes through all Emailed Tasks created TODAY and to update their associated LEAD with today's date.

 

 

Cool_DevloperCool_Devloper

Well, yes that should work out, assuming the number of records are not too huge!

But that would need someone to do a manual click, right?

Cool_D

B2AB2A

Yes, it would require a manual click but far more faster.  Also, I just realized that you can just mass update records from a list view by selected which ever record(s) (or select all) and do inline editting and choose to apply the field update to all selected records!

 

 

This was selected as the best answer
Cool_DevloperCool_Devloper

Woww....i nevaa noticed that till now :P

That would work well for you then. Just you need to create a view as per your criteria and update the requisite records!

Cool_D

B2AB2A
Ya, well the view is no problem.  So I guess this is a time saving workaround .. for now!!