4

I'm trying to create a button which will pull emails from a list view and push them to an empty email template. It is for a custom object (Students_Programs__c) which has a custom formula field for emails (Email__c) which pulls the email from the contact associated with the record.

The problem I have run into so far is that it gets to the blank email template but populates emails as "undefined". I haven't been able to figure out why it is doing this which is unsurprising as I know next to nothing about javascript and have really just been hacking up and splicing code I have found through online searching.

Here's what I have though.

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

    var emailAddresses = ''; 
    var records = {!GETRECORDIDS($ObjectType.Students_Programs__c)}; 
    if (records[0] == null) {
    alert("Please select at least one person to email.");
    } else {
    for(var c = 0; c < records.length; c++) 

    { var contactRecord = sforce.connection.query(
    "SELECT Email__c FROM Students_Programs__c WHERE Id ='"+ records[c]+"'"); 

    emailAddresses = emailAddresses + contactRecord.records.Email + ";"; } }

    location.replace('/email/author/emailauthor.jsp?retURL=/a0F/o&rtype=003&p24='+emailAddresses);
2
  • 1
    Java != Javascript
    – Adrian Larson
    Commented Feb 5, 2016 at 16:34
  • 1
    you are querying for field email__c but trying to build up emailAddresses using field email
    – cropredy
    Commented Feb 5, 2016 at 19:14

1 Answer 1

1

Try to Replace you code:

{ var contactRecord = sforce.connection.query(
    "SELECT Email__c FROM Students_Programs__c WHERE Id ='"+ records[c]+"'"); 

    emailAddresses = emailAddresses + contactRecord.records.Email__c+ ";"; } }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .