Building My Dev Cred

…And building a trigger that creates a new task when an email was sent! 

In 2018, I’m focusing on building my “dev cred,” as Leah McGowen-Hare put it at Forcelandia a few years ago.

Next week is the final week of my RAD Women coding course and I am thrilled with how far I have come.

I am also building more connections in the Salesforce digital communities of Trailblazer, Power of Us Hub and Twitter.

So I was checking out the unanswered questions on the Trailblazer Community to see if I could help out and I ran into this one:

Is it possible to use Process Builder or Workflow in auto creating a task after an email is sent related to a record? The email (with a specific Subject filter) will be sent from (A) within Salesforce or (B) Gmail/Outlook but will be recorded in the Activity History. I tried to create a WR but it didn’t run after I sent an email.

The answer to that is ‘No.’ The end.

Just kidding.

Another user and I asked a few more questions to clarify. We are not talking about sending an email through process builder and creating a task to log that email. We are talking about clicking the “Send an Email” button on a contact, which stores as an activity. Can a follow-up task be automatically created?

I realized I could probably create a trigger for this. Over the past year or two, I have thought this a lot: I think I know enough to cobble some code together and make something work, but an hour or so later, I would give up in frustration. But not today!

I didn’t cobble any code together – I wrote my own successful Apex Trigger and Trigger Handler class from scratch!*

The simply delightful trigger waits for a new task with the subject starting with “Email:” (this is what happens when you send an email through Salesforce) attached to a contact. It then creates a high priority follow-up task with the date set one month from today! I DID IT! SO SATISFYING!

I told my friend @tgeorgelearned about my success. After giving me a high five, he reminded me to write the test class, and then reminded me that I know how to write Test Classes. And I did.

Huge thanks to the women in my RAD Women code group (#crazytownbananapants) and my wonderful coaches, Laura Meerkatz and Beth Briesnes! Also many thanks to @tgeorgelearned for teaching me to fish.

Resources:

Let’s See the Code!

Here’s a little video of my code in action. (All the data is sample data).

Apex Test Class

Apex Trigger Handler

Task Trigger

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s