0

I am trying to write an Apex class that will send emails to my project contacts. Still, I do face one error. I am not sure what I am doing wrong cause I am a beginner in Apex.

public class SendIMRMonthlyEmails {
    
    @InvocableMethod
    public static void invokeapex(list<Project_Contacts__c>ProjectContacts){
        List<Id> contactIds = new List<Id>();
        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
        EmailTemplate et=[Select id from EmailTemplate where name = :System.Label.Sent_IMR_Monthly_Email_Project_Contacts limit 1];
        for(Project_Contacts__c objProject_Contacts__c:ProjectContacts){
                contactIds.add(objProject_Contacts__c.Id);
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTargetObjectId(objProject_Contacts__c.Id);
                mail.setSenderDisplayName('System Admin');
                mail.setTemplateId(et.id);
                mail.setBccAddresses(new List<String> {System.Label.Sent_IMR_Monthly_Email_BCC_Email});
                emailList.add(mail);
            
        }
        
        Messaging.sendEmail(emailList);
    }
    
}
1
  • Which line is the error and what is the full error?
    – RedDevil
    Commented Nov 12, 2021 at 9:10

1 Answer 1

2

This is because you are declaring a variable (on this case on for-loop) with invalid double underscore c (objProject_Contacts__c).

You should something like projectContact.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .