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
Building RadarBuilding Radar 

Apex Trigger on Lead Activity History

Hi everyone,
I wanted to create a trigger that updates a custom checkbox field (Contacted__c) after I have sent an email. Since I am sending the mail from Gmail and logging it to Salesforce via an app called Ebsta, the email appears in "Activity History" only.
Being new to programming, I would greatly appreciate some help on how to write an apex trigger that updates the "Contacted" field when "Activity History" is not empty.
Many thanks for your help!
Cheers, 
Lawrence
sharathchandra thukkanisharathchandra thukkani
Create a workflow on task object and select the field update action where you can update your Master object field Contacted__c.

No need of writing trigger for this.
sharathchandra thukkanisharathchandra thukkani
User-added image
sharathchandra thukkanisharathchandra thukkani
You cannot update the master object field using field update on task obejct. sorry for wrong solution. You can go for trigger on task object with after insert event and take the WhatId, and through Whatid you can update the contacted__c = true and update the field.
Building RadarBuilding Radar
Hi Sharathchandra, thanks for your fast reply. Are you certain, however, that it will work like this? I want the field to get updated automatically, after adding the first mail sent to Salesforce. Also, I have no idea what to put into the evaluation criteria, since I cannot select Activity History as any of the possible fields to be evaluated there. That is why I believed this to be something that can only be solved via Apex.