You need to sign in to do that
Don't have an account?
Missy Longshore
Button for list view not working but passed syntax check
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);
}
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);
}
One limitation: the code only pulls around 85 email addresses. If you have more than that it seems that the rest are just ignored. I don't know why that limitation exists -- but I tested the old code (from a few weeks ago) too and it had the same limitation. Maybe it's a JavaScript string length limit?
Jeremy
All Answers
Try to replace this line and check if it still gives the error..just to check
Thanks,
Sandeep
Jeremy
I help people use Salesforce.
One limitation: the code only pulls around 85 email addresses. If you have more than that it seems that the rest are just ignored. I don't know why that limitation exists -- but I tested the old code (from a few weeks ago) too and it had the same limitation. Maybe it's a JavaScript string length limit?
Jeremy
Mozilla Firefox is the most capable browser. Salesforce only allows me to select 200 records at a time in a Contact list view, and when I tested 200 records, each with 2 email addresses, the code worked beautifully -- FAST (almost instantaneous), and 400 email addresses accounted for.
So... I recommend ONLY using Mozilla Firefox with the functionality in this code.