• Jeremy Bergtholdt
  • NEWBIE
  • 40 Points
  • Member since 2014


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi, I created a custom button on Contacts to display on list views to pull out email addresses. I tried updating it to include Assistant Email addresses with the text in bold and it's no longer working. It passed the syntax check but when I click the button in Salesforce on a list view I get the error message A problem with the OnClick JavaScript... 'expected a ')'.' Any ideas where I missed a closing parentheses? Thanks for your help! 

Here's the code:

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

var records = {!GETRECORDIDS($ObjectType.Contact)}; 
var recipients = []; 

if (records[0] == null) { 
  alert("Please select at least one row."); 

else { 
  // Iterate through records 
  for (var n=0; n<records.length; n++) { 
    // retrieve Contact based on the ID in records 
    var contactLookup = 
sforce.connection.retrieve("Email,Assistant_Email__c","Contact",[records[n]]);
    if(contactLookup[0].Email)
    if(contactLookup[0].Assistant_Email__c) { 
      // email is not empty so add to list 
      recipients.push(contactLookup[0]); 
    } 
  } 

  // Build the string for a mass email 
  // Change the seperator between a semi-colon or comma, depending on 
//email client 
  var toEmailString = ""; 
  for (var n=0; n<recipients.length; n++) { 
    toEmailString = toEmailString + recipients[n].Email + "; "; 
  } 

  // Remove last comma or semi-colon from string 
  toEmailString = toEmailString.slice(0,toEmailString.length-2); 

   //alert("to:"+toEmailString); 
   prompt("Copy and paste this string into your email To: field", 
toEmailString); 

}
Hi, I created a custom button on Contacts to display on list views to pull out email addresses. I tried updating it to include Assistant Email addresses with the text in bold and it's no longer working. It passed the syntax check but when I click the button in Salesforce on a list view I get the error message A problem with the OnClick JavaScript... 'expected a ')'.' Any ideas where I missed a closing parentheses? Thanks for your help! 

Here's the code:

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

var records = {!GETRECORDIDS($ObjectType.Contact)}; 
var recipients = []; 

if (records[0] == null) { 
  alert("Please select at least one row."); 

else { 
  // Iterate through records 
  for (var n=0; n<records.length; n++) { 
    // retrieve Contact based on the ID in records 
    var contactLookup = 
sforce.connection.retrieve("Email,Assistant_Email__c","Contact",[records[n]]);
    if(contactLookup[0].Email)
    if(contactLookup[0].Assistant_Email__c) { 
      // email is not empty so add to list 
      recipients.push(contactLookup[0]); 
    } 
  } 

  // Build the string for a mass email 
  // Change the seperator between a semi-colon or comma, depending on 
//email client 
  var toEmailString = ""; 
  for (var n=0; n<recipients.length; n++) { 
    toEmailString = toEmailString + recipients[n].Email + "; "; 
  } 

  // Remove last comma or semi-colon from string 
  toEmailString = toEmailString.slice(0,toEmailString.length-2); 

   //alert("to:"+toEmailString); 
   prompt("Copy and paste this string into your email To: field", 
toEmailString); 

}