这是我使用 APEX 编写的第一段代码,所以我正在学习……了解一点 Java(达到研究生水平),但我不知道为什么这不起作用。
我知道它没有像之前告诉我的那样给销售人员一个错误(因此最后注释掉了调试。我更改了联系人电子邮件,它只是这样做了,但我没有收到任何电子邮件!这是代码,谢谢你有什么帮助!
trigger Test1 on Contact (after update) {
//IF Email has changed (look at the old email and compare to new)
if(trigger.old[0].Email != trigger.new[0].Email){
//Commit current transaction, reserver email capacity
Messaging.reserveSingleEmailCapacity(1);
//Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//List<Messaging.SendEmailResult> results = new list<Messaging.SendEmailResult>();
//hold email address
String[] toAddresses = new String[] {trigger.new[0].Email};
//Assign new address string
mail.setToAddresses(toAddresses);
//specify return ad (assuming as being sent from server)
mail.setReplyTo('XXX@example.com');
//sender name
mail.setSenderDisplayName('Mr Apex Tester');
//Subject Specification
mail.setSubject('Subjected to Learning');
//And... the content
mail.setPlainTextBody('You have just changed your SalesForce contact email from ' + trigger.old[0].Email + ' to ' + trigger.new[0].Email + '. If this was not intentional please log back into Salesforce.com and ammend you details.');
//if (!results.get(0).isSuccess()){
//System.debug('That didnt really work did it? Reason: ' + results.get(0).getErrors()[0].getMessage());
}
}