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
Eric FischlEric Fischl 

Trigger check value of related field to fire

Hi, simple question here that's stumping me: I have a trigger on EmailMessage that I only want to fire if a checkbox on the related Case object = True. Trolling the forums has got me close but I'm still missing something ... any help greatly appreciated! Incomplete code snippet:
trigger EmailMessageCopyToCaseComments on EmailMessage (after insert) {
for(email e : [Select Initial_Email_Received__c From Case Where Id = :email.parentID    {
    if(!c.Initial_Email_Received__c = 'TRUE' {
           EmailMessageCopyToCaseCommentsTrigger.copyEmailMessagesToCaseComments(Trigger.new);}
}

 
PriyaPriya (Salesforce Developers) 
Hey Eric,

In the requirement you have mentioned that you want to fire email if the checkbox is true. But in the IF condition you are using the NOT Equal to operator. Try to replace it like below :- 
if(c.Initial_Email_Received__c = 'TRUE' {
           EmailMessageCopyToCaseCommentsTrigger.copyEmailMessagesToCaseComments(Trigger.new);}
}


Kindly mark it as the best answer if it helps,

Regards,

Priya Ranjan

Eric FischlEric Fischl
Thanks, Priya ... but the question is how exactly to reference values in an object that's NOT the trigger's object, in order to act on the trigger's logic.
Basically I need to:

1. Determine if the value of a checkbox on CASE is true or false
2. If true, fire the trigger on EmailMessage

I'm getting myself sideways trying to find the proper spot to fetch that CASE value (and sorry, I'm not a developer but filling in for one). Any help greatly appreciated!