现在位置:
首页 > Salesforce > 正文
salesforce发送email
首先,我们要设置一下,否则你是无论怎么怼,你都收不到任何邮件:
Have a look under Setup > Email Administration > Deliverability.
Newly created sandboxes have the default email deliverability set to "System email only."
The options are:
- No access: Prevents all outbound email to and from users.
- System email only: Allows only automatically generated emails, such as new user and password reset emails.
- All email: Allows all types of outbound email. Default for new, non-sandbox organizations.
都看得懂,我就不解释了。
- publicvoidSendEmail(){
- List<User> userlist=[select Id,Email from User where name='Bruce He' limit 1];
- List<String> toUserId =newList<String>();
- List<String> toAddress =newList<String>();
- for(User c:userlist){
- toAddress.add(c.Email);
- toUserId.add(c.Id);
- }
- EmailTemplate et=[Select id from EmailTemplate where developerName ='Alert_Clean_Expire_Msg_Error' limit 1];
- if(toUserId.isEmpty()|| toAddress.isEmpty()|| et==null){
- return;
- }
- Messaging.SingleEmailMessage mail =newMessaging.SingleEmailMessage();
- mail.setTargetObjectId(toUserId[0]);
- mail.setToAddresses(toAddress);
- mail.setTemplateId(et.id);
- mail.setSaveAsActivity(false);
- system.debug(mail);
- Messaging.sendEmail(newMessaging.SingleEmailMessage[]{ mail });
- }
参考内容:
1.https://salesforce.stackexchange.com/questions/12351/send-test-email-from-sandbox
2.https://developer.salesforce.com/forums/?id=906F00000008z98IAA
3.https://developer.salesforce.com/forums/?id=906F0000000DDszIAG
OVER
============ 欢迎各位老板打赏~ ===========
【上篇】Annual Global Change and Configuration Management Process Training and Certification
【下篇】mysql update触发器
【下篇】mysql update触发器
与本文相关的文章
- · Salesforce VisualForce 使用apex:actionFunction调用后台方法
- · How to Call Salesforce API from Lightning Component
- · apex highlight userDefineLang for notepad++
- · 详解 Salesforce 15 和 18 位的ID
- · Salesforce Test class注意事项
- · salesforce Milestone clock is not running
- · salesforce apex traced the number of query
- · salesforce antscript无法拉取完整的profile
- · salesforce lightning report取URL参数
- · salesforce test class用现有数据测试
- · salesforce report get url parameters
- · salesforce display trigger error