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
Nadav GrossNadav Gross 

Trigger: Email sent to lead

Hi everyone,

First time poster, long time reader :)

I would like to have a date/time field updated in a lead record whenever an email is sent to the lead; Sometimes we send emails from within the platform, but sometimes from our gmail account directly (we use Salesforce Inbox for automatic activity capture).

Is this possible? How would one go about creating such a trigger?
Shawn Reichner 29Shawn Reichner 29
I would try to create an after insert trigger on the Activity Object statign when an Activity is created with an WhoID that starts with 00Q , then update the record in the ParentID field (Which is your Lead) to update the date field you created to NOW()

Hope this helps, if you need help with the trigger code, please advise,

Shawn
Nadav GrossNadav Gross
Thanks for the response, Shawn!

Just to be clear: If I send an email out from my regular email (associated with Inbox), does this create an activity? And could you explain the WhoID thing?
Shawn Reichner 29Shawn Reichner 29
If you are using the Salesfroce Inbox which creates an Activity on the Lead record that is referenced, then you should create an activity.  Please check your settings there and maybe test one to see.  

As far as the WhoId, that is the API name of the lookup feild on an activity record that states what Lead or Contact that Activity is placed on. 

Hope that helps,

Shawn
Nadav GrossNadav Gross

Hey Shawn,

Took me a while to experiment with this, but unfortunately, I am still struggling; I have tried querying the database for both Email Message and Task after sending an email to the lead (even from Salesforce itself and not from my Gmail box), but those emails do not show up in either of these databases. It is very bizzare, but Email Message generally seems very empty and only includes a few test emails I have sent myself before connecting Inbox. It seems as if connecting Inbox bypasses the Email Message database completely.

As for task, I have set the trigger and it works properly when I add a task, but not when I send an email or receive an email from the lead. When I query the Task database, I see my tasks and logged calls, but no emails at all.

So the real question is, where the heck are those emails stored when using Inbox.

Appreciate anyone's input on this!