function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Sending to mutiple emails with Flex toolkit

I'm trying to send email to muliple addresses using the Flex toolkit and I can't seem to get it to work.  I'm able to send to a single email addresses.

I've tried passing the following to the "toAddresses" property of the SingleEmailMessage object:
    1. a comma seperated string i.e. ","
    2. an array

When I try to pass an array, Flex gives a compliation error, stating "toAddresses" is expecting a String.

Any ideas?
Hi bryano,

Well, it appears that you found a bug in the sendEMail function in the flex toolkit.  The address fields (to, bcc, cc) should all be string arrays.  The SingleEmailMessage defined those fields as strings.  I have fixed and tested this issue. 

To temporarily work around the issue until we publish a new cut of the toolkit, you can create a new SingleEmailMessage class that has the correct address type definitions.  I've created one below that you can use in your project.

 import com.salesforce.XmlWriter;
 import com.salesforce.objects.BaseEmail;
 import flash.utils.*;
 import mx.utils.ObjectProxy;

 public class MySingleEmailMessage extends BaseEmail
  public var bccAddresses:Array; 
  public var toAddresses:Array;
  public var ccAddresses:Array;
  public var htmlBody:String;
  public var charset:String;
  public var plainTextBody:String;
  public var targetObjectId:String;
     public static const HIGHETS:String = "Highest";
     public static const HIGH:String = "High";
     public static const NORMAL:String = "Normal";
     public static const LOW:String = "Low";
     public static const LOWEST:String = "Lowest";

  public function MySingleEmailMessage(obj:ObjectProxy = null) { 
   for (var key:String in obj) {
    this[key] = obj[key];

  public function toXml(sobjectNs:String, name:String, writer:XmlWriter):void
      writer.writeStartElement(name, sobjectNs);
      writer.writeXsiType('SingleEmailMessage');  // need to apply our own xsi type

      var classInfo:XML = describeType(this); // used to walk thru the variable names of this class
      for each (var v:XML in classInfo..variable) {
           var propName:String = v.@name;
             var propVal:Object = this[propName];
             if (!propVal) continue;   // skip empty properties
          if (propVal is Array) {
              for (var propArrayVal:String in propVal) {
                  writer.writeNameValueNode( propName, propVal[propArrayVal]);
          } else {
           writer.writeNameValueNode( propName , propVal);
      writer.writeEndElement(name, sobjectNs);


Below is a sample of using this class instead of the SingelEmailMessage class:

 private function makeEmailMessage(subject:String, toAddress:Array, body:String, priority:String):BaseEmail {
var single:MySingleEmailMessage = new MySingleEmailMessage();
single.subject = subject;
single.toAddresses = toAddress;
single.plainTextBody = body;
single.emailPriority = MySingleEmailMessage.LOW;
return single;

private function sendEmail() : void {
var emails:ArrayCollection = new ArrayCollection(
[makeEmailMessage("Test Three", ["", ""], "This is the body", SingleEmailMessage.LOW)]

apex.sendEmail( emails.toArray() , new AsyncResponder(
function (result:SendEmailResult):void {
ta.text = 'email Result\n' + ObjectUtil.toString(result) ;
}, genericFault));


We will post in the Ajax Toolkit & SControls board when the fix is publicly available.


Thanks Dave for the work around!