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
dmondmon 

taskTrigger on Case with Assignment Rule

I have 1 assignment rule on Case that assigns user and send email.

Works great with no Triggers on Task or Case.

Then i add this taskTrigger (to Tasks) and the (Case) assignment still works, but not email is sent.

Yes, the assignment rule is to a valid user, email and template (as i said, it works with no trigger).

 

Any ideas?

trigger taskTrigger on Task (before insert) { Case c; for (Task t : Trigger.new) { if(t.WhatId != null){ String s = t.WhatId; if(s.startsWith('500') && t.Status == 'Completed'){ c = [Select Id,Actual_Response_Time__c from Case where Id = :t.WhatId]; if(c.Actual_Response_Time__c == null){ c.Actual_Response_Time__c = System.now(); update c; } } } } }

 

Something in this code is causing my Case assignment rule to not send an email, but it still assigns correctly.

 

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf
Also, you shouldn't be calling update inside the loop.  It's completely unrelated to your problem but it's a best practice.  Save the cases to update in a List<Case> and update them at the end, after you're out of the loop.

All Answers

werewolfwerewolf

That sounds mighty fishy, because by the time your trigger is run, the case will have already been assigned, so they should not be related.

 

Did you look at the trace in a debug log (Setup->Monitoring->Debug Logs) to see if there's something obvious there?

werewolfwerewolf
Also, you shouldn't be calling update inside the loop.  It's completely unrelated to your problem but it's a best practice.  Save the cases to update in a List<Case> and update them at the end, after you're out of the loop.
This was selected as the best answer
werewolfwerewolf
Finally: why in the heck are you doing that with a trigger anyway?  Just make a workflow on Email Message instead with a field update that sets your first response field to NOW().
dmondmon

Sure, i will move to bulk coding once i figure this out.

Nothing in the logs since 2008, so i dont think i can find a solution there.

 

I understand your logic, however i took a much more simple approach.

 

I tried it without the Trigger and it works fine.

I add the Trigger and the issue i descibed happens.

Remove the Trigger, works perfect.

 

Any ideas on how to isolate and resolve?

I really dont want to add workflow for this, i should be able to get the intended functionality just by adding the Template Name in the assignment rule.

 

 

werewolfwerewolf
The debug logs only work when you turn them on.  So turn them on and then reproduce your problem, and you'll get logs.  But anyway, try doing it with a workflow instead.
werewolfwerewolf
And when I say use workflow, I'm not saying that you should use workflow to assign your cases, I'm saying you should use workflow to stamp your first response, because you can do that.
dmondmon

thanks wolf, sure i can use workflow, but I should also be able to add a Trigger to a Task and still have the intended functionality from the Case assignment rule work. What if i was trying to accomplish something else.

 

thanks for your advice, i get what you are saying.

now, i just want to know why this wont work, even though i can accomplish it other ways as you suggested, and i appreciate.

dmondmon

 

 

 

Message Edited by dmon on 03-17-2009 05:19 PM
dmondmon

wolf,

 

Turns out it was completely RELATED to my problem (and is best practice).

I removed the update dml and it started working.

 

thanks again, i have used your advice from other posts as well,

Dale