+ Start a Discussion
Ishan Singh 4Ishan Singh 4 

how to set due date to next 7 day for a task in batch class

Prady01Prady01
hi, In apex you can do this.

date dt = date.today() + 7;
system.debug(dt);

Hope this helps!
Prady01
VinayVinay (Salesforce Developers) 
Hi Ishan,

Below is sample snippet.
 
global class dailyCron implements Schedulable {
    public static String CRON_EXP = '0 0 8 * * ? *'; // 8am Every Day

    global static String scheduleIt() {
        dailyCron cron = new dailyCron();
        return System.schedule('Daily Cron', CRON_EXP, cron);
    }


    global void execute(SchedulableContext sc) {

        //Send CRB Emails
        Contact [] cons = [SELECT Id FROM Contact WHERE Last_Email__c <= LAST_N_DAYS:14];

        for(Contact con : cons){
            con.Send_Email_Reminder__c = true;  
        }

        update cons;

    }
}

Below are links for your reference.

http://www.infallibletechie.com/2013/02/expiry-notification-through-email-using.html
https://salesforce.stackexchange.com/questions/187932/date-in-batch-apex-query

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar