Skip to main content

Thanks. however , i have the following batch class for contact global class batchContactUpdate implements Database.Batchable, Database.Stateful, Schedulable { public final string query; global set UIds; global set BIds; public boolean flag; public string status; public static String CRON_EXP = '0 0 15 * * ?'; list uptlst = new list();

global class batchContactUpdate implements Database.Batchable<sObject>, Database.Stateful, Schedulable { public final string query; global set<Id> UIds; global set<Id> BIds; public boolean flag; public string status; public static String CRON_EXP = '0 0 15 * * ?'; list<Contact> uptlst = new list<Contact>(); global void execute( SchedulableContext SC ) { // check to see if available slots first, otherwise re-schedule batchContactUpdate batch = new batchContactUpdate(); Database.executeBatch( batch, 1 ); } global Database.QueryLocator start(Database.BatchableContext BC) { datetime datePlus30 = System.now().addMinutes( 30 ); if(Test.isRunningTest()){ return database.getqueryLocator ([select Id,lastname,firstname from Contact limit 100]) ; } else{ return database.getqueryLocator ([select Id,lastname,firstname from Contact]) ; } } global void execute(Database.BatchableContext BC, List<Contact> scope) { for(Contact c : scope) { if(flag == true) c.lastname = 'true'; else {c.lastname = 'testfalse';} c.newpakge__Flag_Test__c = true; uptlst.add(c); } update uptlst; } global void finish(Database.BatchableContext BC) { messaging.singleEmailMessage mail = new messaging.singleEmailMessage(); AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CompletedDate, ExtendedStatus, ApexClass.name, CreatedBy.Email, CreatedBy.Name FROM AsyncApexJob WHERE Id =:BC.getJobId()]; mail.ToAddresses = new string[]{ a.CreatedBy.Email,'[email protected]'}; 

// mail.setReplyTo(''); // <-----------------------------------Set the ReplyTo--- mail.setSubject('Batch Code Complete -- '+a.ApexClass.name); mail.setUseSignature(false);

// mail.setReplyTo(''); // <-----------------------------------Set the ReplyTo--- mail.setSubject('Batch Code Complete -- '+a.ApexClass.name); mail.setUseSignature(false); string td1='"border:1px solid green; width=200px;"'; string td2='"width=200px; border:1px solid green; background-color:red; color:white; font-weight:bold;"'; string tdHead='"border:1px solid green; width=200px; color:white; background-color:green; font-weight:bold;"'; string ExtendedStatus=''; if(a.ExtendedStatus!=null) ExtendedStatus=a.ExtendedStatus; string tdErrors=td1; if(a.NumberOfErrors>0) tdErrors=td2; string htmlBody = '<div style="border:2px solid green; border-radius:15px;"><p>Hi,</p><p><span style="color:brown; font-weight:bolder;">Salesforce</span> completed running <b>Apex Batch Code<>/b>.</p>' +'<p>Results:</p>' +'<center><table style="border:3px solid green; border-collapse:collapse;">' +'<tr><td style='+tdHead+'>Class Name</td><td style='+tdHead+'>'+a.ApexClass.name+'</td></tr>' +'<tr><td style='+td1+'>Completed Date</td><td style='+td1+'>'+a.CompletedDate+'</td></tr>' +'<tr><td style='+td1+'>Status</td><td style='+td1+'>'+a.Status+'</td></tr>' +'<tr><td style='+td1+'>Job Items Processed</td><td style='+td1+'>'+a.JobItemsProcessed+' / '+a.TotalJobItems+'</td></tr>' +'<tr><td style='+td1+'>NumberOfErrors</td><td style='+tdErrors+'>'+a.NumberOfErrors+'</td></tr>' +'<tr><td style='+td1+'>Extended Status</td><td style='+td1+'>'+ExtendedStatus+'</td></tr>' +'<tr><td style='+tdHead+'>Created By</td><td style='+tdHead+'>'+a.CreatedBy.Name+' ('+a.CreatedBy.Email+')</td></tr>' +'</table></center>' +'<p>Enjoy the <b>results</b>!</p><p><span style="font-family:"Courier New", Courier, monospace; color:green; font-weight:bold; font-size:larger;">Scott</span></p></div>'; mail.setHtmlBody(htmlBody); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); mails.add(mail); Messaging.sendEmail(mails); } } 

} but it is not helping me even i have wrote a scheduler class. Any help to start appreciated!!

Thanks. however , i have the following batch class for contact global class batchContactUpdate implements Database.Batchable, Database.Stateful, Schedulable { public final string query; global set UIds; global set BIds; public boolean flag; public string status; public static String CRON_EXP = '0 0 15 * * ?'; list uptlst = new list();

global void execute( SchedulableContext SC ) { // check to see if available slots first, otherwise re-schedule batchContactUpdate batch = new batchContactUpdate(); Database.executeBatch( batch, 1 ); } global Database.QueryLocator start(Database.BatchableContext BC) { datetime datePlus30 = System.now().addMinutes( 30 ); if(Test.isRunningTest()){ return database.getqueryLocator ([select Id,lastname,firstname from Contact limit 100]) ; } else{ return database.getqueryLocator ([select Id,lastname,firstname from Contact]) ; } } global void execute(Database.BatchableContext BC, List<Contact> scope) { for(Contact c : scope) { if(flag == true) c.lastname = 'true'; else {c.lastname = 'testfalse';} c.newpakge__Flag_Test__c = true; uptlst.add(c); } update uptlst; } global void finish(Database.BatchableContext BC) { messaging.singleEmailMessage mail = new messaging.singleEmailMessage(); AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CompletedDate, ExtendedStatus, ApexClass.name, CreatedBy.Email, CreatedBy.Name FROM AsyncApexJob WHERE Id =:BC.getJobId()]; mail.ToAddresses = new string[]{ a.CreatedBy.Email,'[email protected]'}; 

// mail.setReplyTo(''); // <-----------------------------------Set the ReplyTo--- mail.setSubject('Batch Code Complete -- '+a.ApexClass.name); mail.setUseSignature(false);

string td1='"border:1px solid green; width=200px;"'; string td2='"width=200px; border:1px solid green; background-color:red; color:white; font-weight:bold;"'; string tdHead='"border:1px solid green; width=200px; color:white; background-color:green; font-weight:bold;"'; string ExtendedStatus=''; if(a.ExtendedStatus!=null) ExtendedStatus=a.ExtendedStatus; string tdErrors=td1; if(a.NumberOfErrors>0) tdErrors=td2; string htmlBody = '<div style="border:2px solid green; border-radius:15px;"><p>Hi,</p><p><span style="color:brown; font-weight:bolder;">Salesforce</span> completed running <b>Apex Batch Code<>/b>.</p>' +'<p>Results:</p>' +'<center><table style="border:3px solid green; border-collapse:collapse;">' +'<tr><td style='+tdHead+'>Class Name</td><td style='+tdHead+'>'+a.ApexClass.name+'</td></tr>' +'<tr><td style='+td1+'>Completed Date</td><td style='+td1+'>'+a.CompletedDate+'</td></tr>' +'<tr><td style='+td1+'>Status</td><td style='+td1+'>'+a.Status+'</td></tr>' +'<tr><td style='+td1+'>Job Items Processed</td><td style='+td1+'>'+a.JobItemsProcessed+' / '+a.TotalJobItems+'</td></tr>' +'<tr><td style='+td1+'>NumberOfErrors</td><td style='+tdErrors+'>'+a.NumberOfErrors+'</td></tr>' +'<tr><td style='+td1+'>Extended Status</td><td style='+td1+'>'+ExtendedStatus+'</td></tr>' +'<tr><td style='+tdHead+'>Created By</td><td style='+tdHead+'>'+a.CreatedBy.Name+' ('+a.CreatedBy.Email+')</td></tr>' +'</table></center>' +'<p>Enjoy the <b>results</b>!</p><p><span style="font-family:"Courier New", Courier, monospace; color:green; font-weight:bold; font-size:larger;">Scott</span></p></div>'; mail.setHtmlBody(htmlBody); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); mails.add(mail); Messaging.sendEmail(mails); } 

} but it is not helping me even i have wrote a scheduler class. Any help to start appreciated!!

Thanks. however , i have the following batch class for contact

global class batchContactUpdate implements Database.Batchable<sObject>, Database.Stateful, Schedulable { public final string query; global set<Id> UIds; global set<Id> BIds; public boolean flag; public string status; public static String CRON_EXP = '0 0 15 * * ?'; list<Contact> uptlst = new list<Contact>(); global void execute( SchedulableContext SC ) { // check to see if available slots first, otherwise re-schedule batchContactUpdate batch = new batchContactUpdate(); Database.executeBatch( batch, 1 ); } global Database.QueryLocator start(Database.BatchableContext BC) { datetime datePlus30 = System.now().addMinutes( 30 ); if(Test.isRunningTest()){ return database.getqueryLocator ([select Id,lastname,firstname from Contact limit 100]) ; } else{ return database.getqueryLocator ([select Id,lastname,firstname from Contact]) ; } } global void execute(Database.BatchableContext BC, List<Contact> scope) { for(Contact c : scope) { if(flag == true) c.lastname = 'true'; else {c.lastname = 'testfalse';} c.newpakge__Flag_Test__c = true; uptlst.add(c); } update uptlst; } global void finish(Database.BatchableContext BC) { messaging.singleEmailMessage mail = new messaging.singleEmailMessage(); AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CompletedDate, ExtendedStatus, ApexClass.name, CreatedBy.Email, CreatedBy.Name FROM AsyncApexJob WHERE Id =:BC.getJobId()]; mail.ToAddresses = new string[]{ a.CreatedBy.Email,'[email protected]'}; // mail.setReplyTo(''); // <-----------------------------------Set the ReplyTo--- mail.setSubject('Batch Code Complete -- '+a.ApexClass.name); mail.setUseSignature(false); string td1='"border:1px solid green; width=200px;"'; string td2='"width=200px; border:1px solid green; background-color:red; color:white; font-weight:bold;"'; string tdHead='"border:1px solid green; width=200px; color:white; background-color:green; font-weight:bold;"'; string ExtendedStatus=''; if(a.ExtendedStatus!=null) ExtendedStatus=a.ExtendedStatus; string tdErrors=td1; if(a.NumberOfErrors>0) tdErrors=td2; string htmlBody = '<div style="border:2px solid green; border-radius:15px;"><p>Hi,</p><p><span style="color:brown; font-weight:bolder;">Salesforce</span> completed running <b>Apex Batch Code<>/b>.</p>' +'<p>Results:</p>' +'<center><table style="border:3px solid green; border-collapse:collapse;">' +'<tr><td style='+tdHead+'>Class Name</td><td style='+tdHead+'>'+a.ApexClass.name+'</td></tr>' +'<tr><td style='+td1+'>Completed Date</td><td style='+td1+'>'+a.CompletedDate+'</td></tr>' +'<tr><td style='+td1+'>Status</td><td style='+td1+'>'+a.Status+'</td></tr>' +'<tr><td style='+td1+'>Job Items Processed</td><td style='+td1+'>'+a.JobItemsProcessed+' / '+a.TotalJobItems+'</td></tr>' +'<tr><td style='+td1+'>NumberOfErrors</td><td style='+tdErrors+'>'+a.NumberOfErrors+'</td></tr>' +'<tr><td style='+td1+'>Extended Status</td><td style='+td1+'>'+ExtendedStatus+'</td></tr>' +'<tr><td style='+tdHead+'>Created By</td><td style='+tdHead+'>'+a.CreatedBy.Name+' ('+a.CreatedBy.Email+')</td></tr>' +'</table></center>' +'<p>Enjoy the <b>results</b>!</p><p><span style="font-family:"Courier New", Courier, monospace; color:green; font-weight:bold; font-size:larger;">Scott</span></p></div>'; mail.setHtmlBody(htmlBody); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); mails.add(mail); Messaging.sendEmail(mails); } } 

but it is not helping me even i have wrote a scheduler class. Any help to start appreciated!!

Source Link
Saswat
  • 27
  • 3
  • 7

Thanks. however , i have the following batch class for contact global class batchContactUpdate implements Database.Batchable, Database.Stateful, Schedulable { public final string query; global set UIds; global set BIds; public boolean flag; public string status; public static String CRON_EXP = '0 0 15 * * ?'; list uptlst = new list();

global void execute( SchedulableContext SC ) { // check to see if available slots first, otherwise re-schedule batchContactUpdate batch = new batchContactUpdate(); Database.executeBatch( batch, 1 ); } global Database.QueryLocator start(Database.BatchableContext BC) { datetime datePlus30 = System.now().addMinutes( 30 ); if(Test.isRunningTest()){ return database.getqueryLocator ([select Id,lastname,firstname from Contact limit 100]) ; } else{ return database.getqueryLocator ([select Id,lastname,firstname from Contact]) ; } } global void execute(Database.BatchableContext BC, List<Contact> scope) { for(Contact c : scope) { if(flag == true) c.lastname = 'true'; else {c.lastname = 'testfalse';} c.newpakge__Flag_Test__c = true; uptlst.add(c); } update uptlst; } global void finish(Database.BatchableContext BC) { messaging.singleEmailMessage mail = new messaging.singleEmailMessage(); AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CompletedDate, ExtendedStatus, ApexClass.name, CreatedBy.Email, CreatedBy.Name FROM AsyncApexJob WHERE Id =:BC.getJobId()]; mail.ToAddresses = new string[]{ a.CreatedBy.Email,'[email protected]'}; 

// mail.setReplyTo(''); // <-----------------------------------Set the ReplyTo--- mail.setSubject('Batch Code Complete -- '+a.ApexClass.name); mail.setUseSignature(false);

string td1='"border:1px solid green; width=200px;"'; string td2='"width=200px; border:1px solid green; background-color:red; color:white; font-weight:bold;"'; string tdHead='"border:1px solid green; width=200px; color:white; background-color:green; font-weight:bold;"'; string ExtendedStatus=''; if(a.ExtendedStatus!=null) ExtendedStatus=a.ExtendedStatus; string tdErrors=td1; if(a.NumberOfErrors>0) tdErrors=td2; string htmlBody = '<div style="border:2px solid green; border-radius:15px;"><p>Hi,</p><p><span style="color:brown; font-weight:bolder;">Salesforce</span> completed running <b>Apex Batch Code<>/b>.</p>' +'<p>Results:</p>' +'<center><table style="border:3px solid green; border-collapse:collapse;">' +'<tr><td style='+tdHead+'>Class Name</td><td style='+tdHead+'>'+a.ApexClass.name+'</td></tr>' +'<tr><td style='+td1+'>Completed Date</td><td style='+td1+'>'+a.CompletedDate+'</td></tr>' +'<tr><td style='+td1+'>Status</td><td style='+td1+'>'+a.Status+'</td></tr>' +'<tr><td style='+td1+'>Job Items Processed</td><td style='+td1+'>'+a.JobItemsProcessed+' / '+a.TotalJobItems+'</td></tr>' +'<tr><td style='+td1+'>NumberOfErrors</td><td style='+tdErrors+'>'+a.NumberOfErrors+'</td></tr>' +'<tr><td style='+td1+'>Extended Status</td><td style='+td1+'>'+ExtendedStatus+'</td></tr>' +'<tr><td style='+tdHead+'>Created By</td><td style='+tdHead+'>'+a.CreatedBy.Name+' ('+a.CreatedBy.Email+')</td></tr>' +'</table></center>' +'<p>Enjoy the <b>results</b>!</p><p><span style="font-family:"Courier New", Courier, monospace; color:green; font-weight:bold; font-size:larger;">Scott</span></p></div>'; mail.setHtmlBody(htmlBody); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); mails.add(mail); Messaging.sendEmail(mails); } 

} but it is not helping me even i have wrote a scheduler class. Any help to start appreciated!!