1、先创建短信日志类:

2、使用定时器,每隔一天,读取两天内未完成的任务信息
然后插入短信日志里

 global class RemindSalesInfo implements Schedulable {global void execute(SchedulableContext ctx) {//1.根据角色得到所有的销售人员           //2.循环根据销售人员根据id和销售订单的创建时间与现在时间的差查询出出差申请信息     //3.如果查询的记录<=0时提醒,拜访记录如果两天没有四条提醒//4.用新的list统计出这些人员的名单//5.循环这些人员,根据角色得到他们的上级领导,//6.发送短消息//如果相同就返回,节假日不发送set<Holiday> holidays = new set<Holiday>([select ActivityDate from Holiday]);for(Holiday h :  holidays){if(h.ActivityDate == Date.today()){return;}                }Map<Date, specialDate__c> smap= new Map<Date, specialDate__c>();Set<specialDate__c> specialDates = new Set<specialDate__c>([select WorkDay__c from specialDate__c]);for(specialDate__c s : specialDates){                smap.put(s.WorkDay__c , s);}//自动判断星期六、天不发送信息,上班日期要发送Datetime dt = DateTime.now();String dayOfWeek=dt.format('u');if((dayOfWeek == '7' || dayOfWeek == '6') && !smap.containsKey(Date.today())){return;}            List<User> allSales = [SELECT Id, Name, UserRole.ParentRoleId   FROM User where Profile.Name like '%大族粤铭销售业务员%'];List<User> managers = [SELECT Id, Name,phone FROM User where UserRole.DeveloperName = 'ZJL' ];System.debug('allSales=' + allSales.size());DateTime now = System.now();     Datetime lastDateTime = now.addDays(-2);List<User> unSubmitSales = new List<User>();List<User> unSubmitVisiter = new List<User>();//得到所有的经理Map<String, User> leaderMap = new Map<String,User>();List<User> allLeaders = [SELECT id, Name, UserRole.id, UserRole.DeveloperName,phone from User where UserRole.Name like '%经理%' and (not UserRole.Name like '%总经理%')];for(User u : allLeaders){leaderMap.put(u.UserRole.id , u);}//---------查询等于两天时间的出差申请--------------------Map<String, Integer> cMap = new Map<String,Integer>();List<CustomObject2__c> trips = [SELECT Id, CreatedById FROM CustomObject2__c WHERE  CreatedDate >:lastDateTime and CreatedDate <:now ];for(CustomObject2__c c : trips){if(cMap.containsKey(c.CreatedById)){cMap.put(c.CreatedById , cMap.get(c.CreatedById)+1);}else{cMap.put(c.CreatedById , 1);}  }   for(User u : allSales){        String uid = u.id;        //List<CustomObject2__c> trips = [SELECT Id FROM CustomObject2__c WHERE CreatedById =: uid and CreatedDate <:newDateTime];if(!cMap.containsKey(uid)){  unSubmitSales.add(u);                                   }}for(User u : unSubmitSales){        //获得上一级的领导信息 List<User> leaders = new List<User>();if(leaderMap.containsKey(u.UserRole.ParentRoleId)){  User leaderUser = leaderMap.get(u.UserRole.ParentRoleId);leaders.add(leaderUser);}      leaders.addAll(managers);        System.debug('leaders=' + leaders.size());   //发送未提交出差申请的短信;String content = u.Name + ' 两天内还未填写出差申请,请注意!';        SMS.doInsert(content, leaders, 'trip');}//---------查询等于两天时间的拜访记录--------------------Map<String, Integer> visitMap = new Map<String,Integer>();List<CustomObject1__c> visitList = [SELECT Id, CreatedById FROM CustomObject1__c WHERE  CreatedDate >:lastDateTime and CreatedDate <:now ];for(CustomObject1__c c : visitList){if(visitMap.containsKey(c.CreatedById)){visitMap.put(c.CreatedById , cMap.get(c.CreatedById)+1);}else{visitMap.put(c.CreatedById , 1);}  }   for(User u : allSales){        String uid = u.id;        if(!visitMap.containsKey(uid)||visitMap.get(uid)<3){//System.debug(uid);unSubmitVisiter.add(u);  }}System.debug('unSubmitVisiter.size()=' + unSubmitVisiter.size());   for(User u : unSubmitVisiter){        //获得上一级的领导信息         List<User> leaders = new List<User>();  if(leaderMap.containsKey(u.UserRole.ParentRoleId)){    User leaderUser = leaderMap.get(u.UserRole.ParentRoleId);leaders.add(leaderUser);}      leaders.addAll(managers);        System.debug('leaders=' + leaders.size());   //发送提交拜访记录小于3篇的短信;String content = u.Name + ' 两天内填写的拜访记录少于4篇,请注意!';             SMS.doInsert(content, leaders, 'visit');}}
}

3、使用定时器,每天的8-18小时发送短信,星期六,七及假日不发送

global class RemindSales implements Schedulable {global void execute(SchedulableContext ctx) {//如果相同就返回set<Holiday> holidays = new set<Holiday>([select ActivityDate from Holiday]);for(Holiday h :  holidays){if(h.ActivityDate == Date.today()){return;}                }Map<Date, specialDate__c> smap= new Map<Date, specialDate__c>();Set<specialDate__c> specialDates = new Set<specialDate__c>([select WorkDay__c from specialDate__c]);for(specialDate__c s : specialDates){                smap.put(s.WorkDay__c , s);}//自动判断星期六、天不发送信息,上班日期要发送Datetime dt = DateTime.now();String dayOfWeek=dt.format('u');if((dayOfWeek == '7' || dayOfWeek == '6') && !smap.containsKey(Date.today())){return;}List<SMSInfo__c> sis = [SELECT Id, content__c, phone__c, TimeNum__c FROM SMSInfo__c where Status__c = '2' and (type__c = 'visit' or type__c = 'trip') limit 49];for(SMSInfo__c s : sis){//因为里面已经有了更新方法SMS.sendMethod(s.phone__c , s.content__c, s.TimeNum__c);       //SMS.sendMethod('15019179692' , s.content__c, s.TimeNum__c);    }}
}

4、发送短信功能

public class SMS {private String url;private String url1;private String url2;private String result;public SMS(){url='';url1='';url2='';result=''; }//发送一条短信,接收一个电话号码和短信内容,返回一个请求结果状态public String sendSMS (String content,String phone,String exId) {url2 = '&ac='+Label.SMSAccount+'&authkey='+ Label.SMSPassWord +'&cgid=16&c=' + EncodingUtil.urlEncode(content, 'utf8')+'&m='+phone;url1 = 'http://192.168.0.20/OpenPlatform/OpenApi?action=sendOnce';//构造短信接口url格式url = url1 + url2; system.debug('url'+url);//发送http请求,需要在远程站点设置用设置访问的网址url,否则请求会失败           HttpRequest req = new HttpRequest();req.setEndpoint(url);req.setMethod('GET'); req.setTimeout(12000);Http http = new Http();HttpResponse res = http.send(req);System.debug(res.getStatus()+'==============sms result========' +'|'+res.getStatusCode());System.debug('==============sms result2========' +'|'+res.getBody());//测试短信接口返回的状态,100表示已经发送(请求的格式正确,成功连接到短信接口),但是并不代表短信发送到对方手机上//当手机号码为连续的任何数字都会成功并返回100状态XmlStreamReader xsr = new XmlStreamReader(res.getBody());    SMSInfo__c info =[SELECT id,Status__c,msgId__c FROM SMSInfo__c WHERE TimeNum__c=:exId limit 1];xsr.next();while(xsr.hasNext()){if(xsr.isStartElement()){system.debug('name:'+xsr.getLocalName());if(xsr.getLocalName()=='xml'){for(integer i=0;i<xsr.getAttributeCount();i++){if(xsr.getAttributeLocalName(i)=='result'){info.Status__c = xsr.getAttributeValueAt(i);}}    }else if(xsr.getLocalName()=='Item'){for(integer i=0;i<xsr.getAttributeCount();i++){if(xsr.getAttributeLocalName(i)=='msgid'){info.msgId__c = xsr.getAttributeValueAt(i);}}} }xsr.next();}update info;return res.getStatus();}public static void doFutureSend(String phone,String content){SMSInfo__c info = new SMSInfo__c();info.phone__c = phone;info.content__c = content;info.Status__c = '2';//未发送info.TimeNum__c = String.valueOf(DateTime.now().getTime());insert info;sendMethod(phone,content,info.TimeNum__c);}//出差申请与拜访记录插入数据public static void doInsert(String content, List<User> leaders, String type){List<SMSInfo__c> smsList = new List<SMSInfo__c>();DateTime now = System.now();     Datetime lastDateTime = now.addDays(-2);List<SMSInfo__c> infoList = [SELECT Id, content__c, phone__c FROM SMSInfo__c where (addDate__c>: lastDateTime and  addDate__c<:now)  and type__c =: type ];Map<String, SMSInfo__c> infoMap = new Map<String, SMSInfo__c>();for(SMSInfo__c info : infoList){infoMap.put(info.content__c, info);}        Integer i = 0;  if(!infoMap.containsKey(content)){for(User leader : leaders){            SMSInfo__c info = new SMSInfo__c();info.phone__c = leader.phone;info.content__c = content;info.Status__c = '2';//未发送info.type__c = type;info.addDate__c = now; info.TimeNum__c = String.valueOf(DateTime.now().getTime() + i++);smsList.add(info);       }     }insert smsList;        }@future(callout=true)public static void sendMethod(String phoneNum,String content,String exId){SMS s= new SMS();String status ='';status = s.sendSMS(content, phoneNum, exId); }    //验证电话号码是否正确     public boolean isPhoneNumber(String str) {    boolean flag  = false;        Pattern p = Pattern.compile('^[1][3,4,5,8][0-9]{9}$'); // 验证手机号  Matcher m = p.matcher(str);    return m.matches(); }
}

5、定时器

RemindSales r = new RemindSales();
String sch = '0 0 9-18 * * ?';
String jobID = system.schedule('每天9点到18点的每小时0分运行一次', sch, r);RemindSalesInfo rs2 = new RemindSalesInfo();
String sch = '0 0 13 * * ?';
String jobID = system.schedule('每天13点运行一次插入未提交“出差申请”和“拜访记录”的业务员的信息到短信', sch, rs2);

Salesforce 发送业务员未提交任务短信提醒经理相关推荐

  1. 国际短信系统平台发送接口说明方法|网页短信平台开发搭建-移讯云短信系统

    国际短信系统平台发送接口说明方法|网页短信平台开发搭建-移讯云短信系统 此接口为发送接口可直接通过pos直接调用 直接发送,源码短信平台搭建平台时 包含此功能,在客户端中可查看API接口文档 接口名称 ...

  2. Android短信的发送和广播接收者实现短信的监听

    Android短信的发送和广播接收者实现短信的监听  要注意Android清单中权限的设置以及广播的注册监听实现 以下就是 Android清单的XML AndroidManifest.xml < ...

  3. nexmo发送成功,但没有收到短信

    nexmo发送成功,没有接收到短信 今天下午公司项目需要java调用nexmo的接口来发送短信,代码如下 import com.nexmo.client.NexmoClient; import com ...

  4. 几招搞定如何发送招聘兼职通知面试短信

    许多的公司企业需要招聘兼职人员,但是确不太会写通知面试短信.而且招聘兼职通知也看准了群发短信成本低廉,覆盖面广,实时送达.直接命中目标客户等优势,纷纷开通短信平台.蝶信互联短信平台专注短信应用行业6年 ...

  5. java短信接口发送的这三种短信,你收到过几种?

    不同的行业应用java短信接口的用途不一样,但大多数都是用于传递消息.加强服务.提高安全性,因而一般情况下java短信接口会发送通知类短信.问候类短信.营销类短信及广告类短信,具体的让我们一起来了解下 ...

  6. 【短信业务】阿里云可以发送带变量的链接短信

    申请开通短信业务流程 阿里云配置短信业务 1.在账号管理中的 Accesskey管理中申请accessKeyId和accessKeySecret 2.进入短信服务管理 3.进入快速学习和测试 申请签名 ...

  7. 应用程序加入短信提醒功能实现全步骤

    应用程序加入短信提醒功能实现全步骤 短信猫提供商的安装光盘下载         在很多应用程序中,特别是企业级 web 应用程序中,有很多时候需要及时提醒用户某些信息.等待用户登录系统后弹出提醒信息, ...

  8. 如何设置好看的form表单样式_Qamp;A| 表单如何设置短信提醒

    Hi,大家好,表姐又来给大家答疑解惑啦!这一期的Q&A答疑我们来聊聊表单该如何设置短信提醒. 表单的短信提醒功能非常有用,通过手机短信及时反馈信息,让你实时掌握数据最新动态,不仅可以设置给表单 ...

  9. 使用ContentObserver实现短信提醒功能

    通过查询语句:Cursor cursor = mContext.getContentResolver().query(Uri.parse("content://sms"), nul ...

最新文章

  1. ASP.NET 下载文件方式
  2. 计算机专业只考408吗,关于计算机考研408的那些事儿
  3. 五、唱歌不如跳舞(下)
  4. Java Review - Java进程内部的消息中间件_Event Bus设计模式
  5. Android之javax.net.ssl.SSLPeerUnverifiedException: Hostname ip not verified:解决办法
  6. Diango博客--23.单元测试:测试 blog 应用
  7. python 文本处理库_实用又好用,6 款 Python 特殊文本格式处理库推荐
  8. python实现高精度加法_蓝桥杯-Python-高精度加法
  9. phpnow修改默认站点根目录的方法
  10. 题解【[BJOI2012]算不出的等式】
  11. Python使用matplotlib可视化模拟正弦余弦在子图显示
  12. python 绘制中国地图并利用经纬度标注散点
  13. sumif单列求和_Sumif、Sumifs单列多条件求和
  14. 让Firefox支持Wap浏览器功能的插件
  15. VM虚拟机安装CentOS7添加硬盘扩展存储空间的方法
  16. Codeforeces——69A Young Physicist
  17. thinkphp 的 whereIN() 、where IN 如何使用?
  18. 1628_MIT 6.828 xv6_chapter0操作系统接口
  19. Go使用qrcode包解析微信和支付宝二维码,生成一个链接(前端拿到链接即可解析成对应的支付二维码)
  20. 今天把积累几年的49个实用工具分享出来,涉及各个方面的工具,进来看一看咯。

热门文章

  1. webGL法线贴图原理
  2. 双向箭头轮播图html,根据 轮播图背景色 自动填充剩余背景色的 走马灯
  3. 三维数组中以行优先和以列优先处于相同存储位置的判别
  4. vlan的基本指令_华为交换机vlan划分常用命令
  5. frp内网穿透——配置windows客户端
  6. 二叉树(递归)遍历流程图怎么画?
  7. 计算机cmd测试命令,常见CMD网络诊断命令
  8. ThinkPHP6.0伪静态使用
  9. C语言人五英尺七英寸,5呎7吋 是多高?
  10. 技术篇——使用 Junit 实现单元测试