I have an After Insert Trigger on Task. This trigger passes data to a handler class that then does some logic and sends an email to the Lead related to the task.
Ideally, I want to save the email as an activity on the Lead record. However, by doing so, this will fire the Trigger again as the activity related to the email is a Task (which will fire another email etc, etc).
I know that it is possible to prevent this with a static variable tracking if its the first or second run and with conditional statements in my Trigger, so it will not send another email. The trigger is still fired for at least 2 times though.
Is it possible to somehow prevent the trigger from firing on the activity insert caused by the sent email? I've looked into trigger context variables and those don't seem to meet my requirements.