Skip to content

Instantly share code, notes, and snippets.

@zaki-yama
Created June 24, 2015 07:30
Show Gist options
  • Select an option

  • Save zaki-yama/5808253ab8de1077e315 to your computer and use it in GitHub Desktop.

Select an option

Save zaki-yama/5808253ab8de1077e315 to your computer and use it in GitHub Desktop.
[Apex]メール送信時に「活動履歴」にも残す
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// この書き方だと活動履歴には残らない
// String[] toAddresses = new String[] { [Toに指定したいアドレス] };
// mail.setToAddresses(toAddresses);
Contact to = [SELECT Id FROM Contact WHERE Id = ...];
mail.setTargetObjectId(c.Id);
List<String> ccAddresses = new List<String> { [Ccに指定したいアドレス] };
mail.setCcAddresses(ccAddresses);
mail.setSubject('Sample mail');
mail.setSaveAsActivity(true); // これが重要
mail.setWhatId( [ケースなどのId] ); // ケースなどのレコードの「活動履歴」にも残す場合
mail.setPlainTextBody('Hello, world!');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment