高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
global class OPDPlanWarningSchedule implements Schedulable {
     global void execute(SchedulableContext sc) {
 
        Date today = Date.today();
        Date mon1stDate = Date.newInstance(today.year(), today.month(), 1);
        Date monLastDate = mon1stDate.addMonths(1).addDays(-1);
        // 本月最后一天的周日
        Date weekStart = monLastDate.toStartofWeek();
        system.debug('wwwwwwwww' + weekStart);
 
        Date lastSecondFriday;
        if (weekStart.addDays(5).month() == today.month()) {
            lastSecondFriday = weekStart.addDays(-2);
        } else {
            lastSecondFriday = weekStart.addDays(-9);
        }
        if(today == lastSecondFriday){
            // 设置一回最多只发40个邮件
            Id execBTId = Database.executeBatch(new OPDPlanWarningBatch(), 40);
            
        }
    }
}