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
Ramana123Ramana123 

Create a field called LiveDate(Date field) on contact. Write a batch to get the contacts whose LiveDate is today and send those contact details to the currently logged in user email and this batch should run every day at 11 am ist

Ramana123Ramana123
plzzzz modify the below code plzzz urgent



global class Live_Date_Batch_Class implements Database.Batchable<sObject>{

        global Live_Date_Batch_Class(){
                   // Batch Constructor
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
        
            string query = 'select id,LastName from Contact WHERE Live_Date__c = TODAY';
            System.debug('aaaaaaaaaaaaaaaaaaaaaaaa'+query) ; 
            return Database.getQueryLocator(query);

        }

      // Execute Logic
       global void execute(Database.BatchableContext BC, List<Contact>scope){
            Set<Id> convertedIdSet = new Set<Id>();
           List<messaging.SingleEmailMessage>  emails = new List<messaging.SingleEmailMessage>();
            for(Contact contact : scope) {
            convertedIdSet.add(contact.id);
        }
 
           
       // opp.CloseDate = 'createddate+1'; 
       Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
       email.setToAddresses(new String[] {'srikanthyeturu123@gmail.com'});
       email.setSubject('opportunity closed date'); 
       email.setPlainTextBody('Dear user, Your opportunity closed date is tommorow');

       emails.add(email);
       
       Messaging.sendEmail(emails);
       
           
       }
            
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }