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
Abby StockerAbby Stocker 

Trigger from related Email Message

Hello! I am just starting out on the development side of SF. We had a company relate email messages with a custom object "claim" so that we were able to route incoming emails back to its associated claim (just like email to case). On the email message object, there is a "Incoming" checkbox field. I would like a "Email Received" checkbox to be put on the claim custom object so I can use it in a flow. The use for it in the flow is as follows: If the "Email Recieved" checkbox is true, DO NOT send email. Any help on how to relate those two checkboxes would be extremely appreciated!! Thank you!!
Abby StockerAbby Stocker
Here is my sad attempt at a code for this? Be nice. lol. This is my first one ever :)

trigger EmailMessage on Claim__c (after insert, after update) {
    For(Claim__c c : Trigger.new){
        EmailMessage[]incomingEmail = [SELECT ToAddress,Incoming FROM EmailMessage];
            if(incomingEmail.Incoming == true){
                c.Email_Recieved__c=true;
            }
        else{
              c.Email_Recieved__c=false;
        }
    }
}