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

Apex Trigger Not Firing - Due to Reference to Fields on a Lookup Record?

I have Apex Triggers in my production environment that are successfully working.  In my sandbox, I recently added two fields on an object (Account) that is referenced via a lookup field on another object (Claim__c).  I then wanted to add those two fields that were added on Account as criteria for when the apex trigger should fire.  Once I added the reference to those two fields, my trigger stopped working.  I think I may be referencing those fields incorrectly and was looking for some hlep.  Below is my trigger and I identified the new code I added to reference the fields on the Account record that is identified through a lookup field on the Claim__c object in red text.


Any help is greatly appreciated, thanks!


***Please note that Acknowledgment_Letter__c is a picklist and Combo_Letter_Instead_of_Acknowledgment__c is a checkbox.


trigger AcknowledgmentLetterTask on Claim__c (before update) {
 List<Task> tasks = new List<Task>();
    for(Claim__c claim :{
    if(claim.Acknowledgment_Letter_Task_Created__c != null &&
         claim.Acknowledgment_Letter_Task_Created__c == false &&
         claim.Approval_Received__c == true &&
         claim.Program_Lookup__r.Acknowledgment_Letter__c == 'Yes' &&
         claim.Insured_Lookup__r.Combo_Letter_Instead_of_Acknowledgment__c != null &&
         claim.Insured_Lookup__r.Combo_Letter_Instead_of_Acknowledgment__c == false


//Do your Task creation
            Task AcknowledgmentTask = new Task();
            AcknowledgmentTask.ActivityDate = claim.LVL_Received_Date__c + 2;   
            AcknowledgmentTask.WhatId =;
            AcknowledgmentTask.OwnerId = claim.Program_Lookup__r.Acknowledgment_Letter_Task_User__c;    
            AcknowledgmentTask.Priority = 'Normal';   
            AcknowledgmentTask.Status = 'Not Started';
            AcknowledgmentTask.Subject = claim.Program_ID__c + ' Acknowledgment Letter -- ' + claim.Insured__C + ' -- ' + claim.Claimant_Name__c;   

//Add the Task
//Update the field on Claim so this isn't done again
claim.Acknowledgment_Letter_Task_Created__c = true;
    insert tasks;


Please ensure that you have set Acknowledgment_Letter__c  with default as 'Yes'. Since for Boolean false is default so that part is ok but for picklist you need to check if you have set default value for picklist as 'Yes'. Else wont work as Accounts already existed in the system.


Importantly In before update for Trigger.New, LookUp relationships Id would come. not the complete Object(Account). You need to get the Id and Query from System for these details .


Something like this 


Id LookupId=claim.Program_Lookup__c;


Select Acknowledgment_Letter__c,Combo_Letter_Instead_of_Acknowledgment__c  from Account where Id = : LookUpId


and then check values.