public with sharing class OppInternalMessageController { String oldResponse; // 询价 public Opportunity ra { get; set; } public Opportunity ra1 { get; set; } public Opportunity cc { get; set; } // 询价ID public Id raid { get; private set; } public Boolean hasError { get; private set; } public String baseUrl { get; private set; } public String usertype { get; private set; } public OppInternalMessageController() { //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8'); baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); raid = ApexPages.currentPage().getParameters().get('raid'); } public OppInternalMessageController(ApexPages.StandardController stdController) { //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8'); baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); raid = stdController.getId(); } // 画面初始化 public void init() { hasError = false; ra = new Opportunity(); cc = new Opportunity(); usertype = UserInfo.getUserType(); List raList = [select Id, Name, InternalMessage__c from Opportunity where Id = :raid]; if (raList.size() > 0) { ra = raList[0]; } } // 画面初始化-POP UP public void init1() { hasError = false; ra1 = new Opportunity(); List ra1List = [select Id, Name, InternalMessage__c from Opportunity where Id = :raid]; if (ra1List.size() > 0) { ra1 = ra1List[0]; } oldResponse = ra1.InternalMessage__c; ra1.InternalMessage__c = ''; } // 保存按钮 public PageReference saveBtn() { hasError = false; String response = ra1.InternalMessage__c; if (response == null || response.trim().length() == 0) { ra1.InternalMessage__c.addError('请输入内容。'); hasError=true; return null; } // 送信者 String username = UserInfo.getName(); // 发送时间 Datetime dt = Datetime.now(); // 现留言 String temp = ''; temp += '****** ' + username + ' ' + dt.format() + ' ******\n'; temp += ra1.InternalMessage__c; if (oldResponse != null && oldResponse.trim().length() > 0) { temp += '\n\n' + oldResponse; } try { // 更新留言 ra1.InternalMessage__c = temp; update ra1; ra1.InternalMessage__c = ''; //Create a dummy instance of outbound email object // Messaging.SingleEmailMessage message= new Messaging.SingleEmailMessage(); //set a roolback point // Savepoint sp = Database.setSavepoint(); //set desired email template id // message.templateId = 'xxxxxx'; //set the target object record id(this is mandatory while using email template) // Id recId = [select Id from Contact where Email != null limit 1].id; // message.targetObjectId = recId; //fire dummy email // messaging.sendEmail(new Messaging.SingleEmailMessage[] {message}); //roll back to savepoint so that email is not sent // Database.rollback(sp); //Create insatnce of actual email Messaging.SingleEmailMessage messageNEW= new Messaging.SingleEmailMessage(); //get the bode from above dummy instance and set it to your actual email //messageNEW.HTMLBody = message.getHtmlBody(); //messageNEW.Subject = '订单' + ra.Name + '' + 'OCN内部留言'; messageNEW.Subject = '询价 ' + ra1.Name + '-内部留言'; messageNEW.PlainTextBody = temp; //set desired email addresses messageNEW.setCharset('UTF-8'); } catch (Exception ex) { system.debug('=====' + ex.getMessage()); hasError = true; ApexPages.addMessages(ex); return null; } return null; } public static void te(){ Integer i = 1; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; } }