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
Bernie XBernie X 

OrgWideEmailAddress x Javascript reference

I'd like to have a button send an e-mail, after an onclick.  I've setup my OrgWideEmailAddress in my sandbox, and can access its ID via SOQL query.  Using the an embedded sendemail API call in Javascript, I get the following error {faultcode:'soapenv:Client', faultstring:'Element {urn:partner.soap.sforce.com}OrgWideEmailAddressId invalid at this location', }.  Can't figure out even what this error means...this location?
Vinita_SFDCVinita_SFDC
Hello,

Please share your javascript code, how are you referring this field in your code.
Bernie XBernie X
Vinita_SFDC,

Thanks for you reply.  Here's my JavaScript:

{!REQUIRESCRIPT ("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

function log(message) {
  alert(message);
}

var d = sforce.connection.query("select ID from OrgWideEmailAddress");
   
var records = d.getArray("records");

sforce.debug.log(d.length);

    for(var i=0;i<records.length;i++){
      var record = records[i];
      sforce.debug.log(record.Id);
      var e = record.Id;
    }

var c = "{!Customer_Correspondences_and_Complaints__c.Name}";

var s = new sforce.SingleEmailMessage();
s.replyTo="berniex@google.com";
s.subject = "Complaint # " + complaint + " is ready for review";
s.OrgWideEmailAddressId = e;

s.plainTextBody = "Complaint # " + c + " is ready for review.\n\nUse the link below to review this complaint.\n\n" + document.URL +"\n\nRegards,\n\n"+"{!$User.FirstName}";

s.toAddresses = ["berniex@google.com"];

sforce.debug.log(s);

var t = sforce.connection.sendEmail([s]);

Vinita_SFDCVinita_SFDC
Hello,

I have three suggestions:

1) Move variable e out of For loop and declare it outside.

2) Try checking value of all the variables using alert staement.

3) Try hardcoding an email address to check if code is working fine and issue is with orgwideemailAddress
Bernie XBernie X
Vinita_SFDC,

Thanks for your reply.  I have tried # 2 and # 3 already (the debug.log commands work similar to alerts and the code works if I don't declare orgwideemailAddressId).  Will give # 1 a shot.