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
Kevin Caballes 10Kevin Caballes 10 

Variable does not exist Error for opportunity field

I am attempting to save the following but keep getting the error:

Error: Compile Error: Variable does not exist: Send_Attachment_Notification_Email__c at line 20 column 17

The API name for the field on the opportuity object is Send_Attachment_Notification_Email__c so I am not sure what I could be doing wrong.
 
trigger attachmentTrigger on Attachment (before insert) {
    // 1. Get List of Object Ids you wish to notify on
    Set<Id> objectIds = new Set<Id>();
    
    // 2. Loop through list of attachments, and if attachment is associated to object you want to notify on, add Parent Id to objectIds set
    for(Attachment a:trigger.new){
        String keyPrefix = string.valueOf(a.ParentId).substring(0, 3);
         
         if(keyPrefix == '500'){
            objectIds.add(a.ParentId);
         }
    }
    
    // 3. Get your objects you want to notify on, and set the Send Attachment Notification Email field to True 
        // This will to fire the workflow rule to send the email
    if(objectIds.size() > 0){
        List<CASE> yourObjectList = [SELECT Id FROM CASE WHERE Id IN :objectIds];
        
        for(CASE obj:yourObjectList){
            obj.Send_Attachment_Notification_Email__c = TRUE;
        }
        
        if(yourObjectList.size() > 0){
            update yourObjectList;
        }       
    }
}

 
Best Answer chosen by Kevin Caballes 10
VinayVinay (Salesforce Developers) 
Hi Kavin,

There is no field 'Send_Attachment_Notification_Email__c' existing on case object.

Can you recheck same?

Thanks,
Vinay Kumar

All Answers

VinayVinay (Salesforce Developers) 
Hi Kavin,

There is no field 'Send_Attachment_Notification_Email__c' existing on case object.

Can you recheck same?

Thanks,
Vinay Kumar
This was selected as the best answer
Marzorati ClaudioMarzorati Claudio
Hi Kevin,

are you sure that in Case object do you have a custom field named Send_Attachment_Notification_Email__c? Be sure of that by navigate throught the object manager.
Maybe a wrong character is your problem.

Be sure that this field is on Case object and not on another object.

Claudio
Chris KChris K
As mentioned by others, 1) check to see if that is a valid field API on the Case object and 2) if it's valid, check your FLS settings
Kevin Caballes 10Kevin Caballes 10
Thanks everyone this was solved, I was looking on the opportuinty object for the field name for some reason