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);
  • 1
    Java != Javascript – Adrian Larson Feb 5 '16 at 16:34
  • 1
    you are querying for field email__c but trying to build up emailAddresses using field email – cropredy Feb 5 '16 at 19:14
0

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+ ";"; } }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.