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
Anuj Joshi 42Anuj Joshi 42 

Future class in a trigger

Hi All,

I have a trigger and a batch class. the class is
global class AsyncApexClass{
@future

public static void sendEmail(Set<Id> sendList){
List <Notes__c> notesList = new List<Notes__c>();
notesList.clear();
for(List<EmailMessage> emailmsglist:[select Id,parentId,Parent.Email__c,Parent.Contact.Email,ToAddress, FromAddress, Subject, TextBody, HTMLBody, CreatedDate from EmailMessage where id in :sendList] )
{
        for(EmailMessage emlist :emailmsglist){

             Notes__c note= new Notes__c(); // Create a note object 
             note.Case__c= emlist.parentid;
                 IF (emlist.HTMLBody != NULL && emlist.HTMLBody != ''){
                 note.Message__c = emlist.HTMLBody;
                 }
                 else {
                 note.Message__c = emlist.TextBody;
                 }    
             note.Sent_To__c = emlist.ToAddress;
             note.From__c = emlist.FromAddress;
             note.Subject__c = emlist.Subject;
             note.Datetime_Created__c = emlist.CreatedDate;
             if (emlist.Parent.Contact.Email == emlist.ToAddress || emlist.Parent.Email__c == emlist.ToAddress) // If the email is the same as Case's contact email or Email__c on Case itself, the type is a response.
             {
             note.Type__c = 'Response';
             }
             else {
             note.Type__c = 'Forward/Others';
             }
             notesList.add(note); // Add note object to the list
         }
}
// If the note list has records, insert the list.
if(notesList.size()>0) {
       insert notesList;
       }
}
}

The triger is
trigger CreateNotes on EmailMessage(after insert) {

    //Variable declaration
    Set<Id> collectEmailSet = new Set<Id>();
    for(EmailMessage  msg : Trigger.New){
      collectEmailSet.Add(msg.Id);
    }
    if(collectEmailSet.size()>0){
            AsyncApexClass.sendEmail(collectEmailSet); 
    }
 }

When i was deploying it to prod I got a error like this "
This Apex class has batch or future jobs pending or in progress". I checked the checkbox in deployment settings option. But after deployment mail is not delivered to users. Do I need to schedule my jobs again?

Thanks,
Anuj
MagulanDuraipandianMagulanDuraipandian
Hi,
Check in Apex Jobs to see whether the job is failing due to errors.
--
Magulan Duraipandian
www.infallibletechie.com
<Saket><Saket>
Hi Anuj,

Please check in that this AsyncApexClass is Scheduled in Scheduled Jobs if yes then delete this schedule job and depoy it again. I hope it will work.

Thanks