• Dharmendra Bhuva
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Describing the goal:
We have a need to send an email to an external email address (which we did) but we also wants salesforce to add a task for this action.

We managed to do this from a  send an email  button in the following way  (you can see in the image)


Screen after we pressed send an email button


The problem is that we can't reproduce this behavior with apex code.
we tried this with the code below : The Email sent but Task not created 

[ Please be advised - we do not want to use message.setTargetObjectId() becuase we don't want to send an email to the contact ]

List<string> toList = new List<string>();
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
toList.add('any@external.email');
message.setUseSignature(false);
message.setSaveAsActivity(true);
message.setSubject('Any subject);
message.setHtmlBody('any Body');
message.setWhatId('00111000007dqTk'); //  THIS IS AN ID OF THE SIMPSON'S FAMILY
message.setToAddresses(toList);
Messaging.sendEmail(message);