You need to sign in to do that
Don't have an account?
jamesmulcahy
We have Email2Case configured to add inbound e-mails to their respective case when they arrive.
I'd like to write a trigger which fires when such an e-mail arrives (so that I can potentially move the case to a different state). I can see two ways of almost achieving this, but I can't find all the pieces of the puzzle.
1. I could create a trigger for when a new task is created, except I can't seem to find a way of getting at the e-mail assocated with the task -- is there a way to do this?
2. I could use the InBoundEmail handler to handle the e-mail, but then I need to manually go about working out which case it relates to, which seems a little heavy handed -- is there a way to have SF give me the Case# for an e-mail if it spots the reference tag?
Is there a simple solution I'm overlooking here?
Cheers
Trigger for when a new e-mail is added to a case
We have Email2Case configured to add inbound e-mails to their respective case when they arrive.
I'd like to write a trigger which fires when such an e-mail arrives (so that I can potentially move the case to a different state). I can see two ways of almost achieving this, but I can't find all the pieces of the puzzle.
1. I could create a trigger for when a new task is created, except I can't seem to find a way of getting at the e-mail assocated with the task -- is there a way to do this?
2. I could use the InBoundEmail handler to handle the e-mail, but then I need to manually go about working out which case it relates to, which seems a little heavy handed -- is there a way to have SF give me the Case# for an e-mail if it spots the reference tag?
Is there a simple solution I'm overlooking here?
Cheers
All Answers
The problem being that the EMailMessage hasn't been created at the point the task is created -- so trying to pull out all the Emails associated with this task always yields zero results.
The code I'm using right now is:
trigger EMailTrigger on Task (after insert) {
for (Task aTask : Trigger.new)
{
EMailMessage[] m = [SELECT FromName, ActivityID from EmailMessage]; // WHERE ActivityID = :aTask.id];
for (EmailMessage aMessage : m)
{
system.debug('Message from ' + aMessage.FromName + ' with ActivityID ' + aMessage.ActivityID + ' task = ' + aTask.id);
}
}
}
Debug from initial run:
20080530113222.675:Trigger.EMailTrigger: line 8, column 7: Message from James Mulcahy with Activity ID00TT0000008QMM8MAO task = 00TT0000008QNprMAG
Debug from followup run:
20080530113415.843:Trigger.EMailTrigger: line 8, column 7: Message from James Mulcahy with Activity ID00TT0000008QNprMAG task = 00TT0000008QNq5MAG
20080530113415.843:Trigger.EMailTrigger: line 8, column 7: Message from James Mulcahy with Activity ID00TT0000008QMM8MAO task = 00TT0000008QNq5MAG
Take note of how there is no e-mail matching the initial task ID until the 2nd run.
Is the InboundEmail route my only choice here? If so, I'm still stumped on how to associate that with a case?
Many thanks for your response!
I am a new user to saleforce, and trying to achieve the same. Appreicate if you could elobrate more on the setup workflow steps
Thanks