public class NFM301SendEmail { // @future (callout=true) // public static void sendEmailOnNFM301(List rectivingNote,List rectivingNoteSum,List rectivingNoteDet,List assetY,List assetN) { public static void sendEmailOnNFM301(List rectivingNoteId,List rectivingNoteSumId,List rectivingNoteDetId,List assetYId,List assetNId) { // 子表单符合条件的List集合 // 查询所有的有效信息 List rectivingNote = [select id,DateOfDelivery__c,Sales_order_number__c,Managment_Code__c from ReceivingNote__c where id = :rectivingNoteId]; List rectivingNoteSum = [select id,Product_Serial_No__c from ReceivingNoteSummary__c where id = :rectivingNoteSumId ]; List rectivingNoteDet = [select id,Product_Serial_No__c from ReceivingNoteDetail__c where id = :rectivingNoteDetId]; List assetY = [select id,Product_Serial_No__c from Asset where id = :assetYId]; List assetN = [select id,Product_Serial_No__c from Asset where id = :assetNId]; // 邮件List集合 Messaging.SingleEmailMessage[] theEmails = new Messaging.SingleEmailMessage[]{}; String emailBody = ''; // 收货清单 if(rectivingNote.size() > 0){ emailBody += '收货清单:
'; for(ReceivingNote__c recenote :rectivingNote){ emailBody += '        Waring! 订单编号('+recenote.Sales_order_number__c+')+发货日期('+recenote.DateOfDelivery__c.format().replace('/', '')+')已存在。不处理收货清单。
'; } } // 收货清单配套一览 if(rectivingNoteSum.size() > 0){ emailBody += '收货清单一览:
'; for(ReceivingNoteSummary__c recenotesum :rectivingNoteSum){ emailBody += '        Waring! '+recenotesum.Product_Serial_No__c+'已存在。不处理收货清单一览。
'; } } // 收货清单配套一览明细 if(rectivingNoteDet.size() > 0){ emailBody += '收货清单一览明细:
'; for(ReceivingNoteDetail__c recenotedet :rectivingNoteDet){ emailBody += '        Waring! '+recenotedet.Product_Serial_No__c+'已存在。不处理收货清单一览明细。
'; } } // 保有设备 if(assetY.size() > 0 || assetN.size() > 0){ emailBody += '保有设备:
'; // emailBody += '    ProcessType(处理方式)=1:新建的时候,
'; if(assetY.size() > 0){ // emailBody += '        收货清单一览明细的收货状态(RND_Status__c)=“待收货”的时候,更新
'; for(Asset yasset :assetY){ emailBody += '        Waring! '+yasset.Product_Serial_No__c+'已存在“待数据确认”的设备。更新保有设备('+yasset.Id+')。
'; } } if(assetN.size() > 0){ // emailBody += '        收货清单一览明细的收货状态(RND_Status__c)<>“待收货”的时候,不更新
'; for(Asset nasset :assetN){ emailBody += '        Waring! '+nasset.Product_Serial_No__c+'已存在不是“待数据确认”的设备。不处理保有设备。
'; } } } // emailBody += ''; // 发件人 List userList = [select id,email from User where name = '精琢 技术']; List emailList = new List(); for(User usr : userList){ emailList.add(usr.Email); } emailList.add('IT_SFDC@olympus.com.cn'); // emailList.add('jhtaizxt@163.com'); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // mail.setToAddresses(new List {'1666755024@qq.com','jhtaizxt@163.com'}); mail.setToAddresses(emailList); mail.setSenderDisplayName('NFM301更新邮件'); mail.setSubject('NFM301更新邮件'); mail.setHtmlBody(emailBody); theEmails.add(mail); // for(Customer__c atr : atrList) { // // 自定义html邮件模版 // String emailBody = '尊敬的'+atr.VipLeve__c +':'+ atr.Name + ':
您好: '+'电影《'+move.Name+'》将在'+move.Release_time__c+'在本电影院上映,欢迎来本电影院观看'; // Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // mail.setToAddresses(new List {atr.Email__c}); // mail.setSenderDisplayName('某某电影院'); // mail.setSubject('观影推送'); // mail.setHtmlBody(emailBody); // theEmails.add(mail); // } Messaging.Email[] allMails = new Messaging.Email[]{}; for(Integer j = 0; j < theEmails.size(); j++) { allMails.add(theEmails.get(j)); } // Messaging.sendEmail(allMails); // 打印错误信息 // Messaging.SendEmailResult[] results = Messaging.sendEmail(allMails); // Messaging.SendEmailError[] errors = new Messaging.SendEmailError[]{}; // String emailErrorReport = ''; // for(Messaging.SendEmailResult currentResult : results) { // errors = currentResult.getErrors(); // if(null != errors) { // for(Messaging.SendEmailError currentError : errors) { // emailErrorReport = emailErrorReport + ' (' + currentError.getStatusCode() + ') ' + currentError.getMessage(); // System.debug(emailErrorReport); // } // } // } System.debug('===========SUCCESS'); } }