0

When we "Task: Send an Email" from an account record, the account is set by default, but one must select a contact to send to. Problem is, the lookup shows contacts from other accounts, so it is easy to choose the wrong contact to send to. I looked for a way to filter these, but could not find this section in setup.

According to this post, filtering the contacts is not possible in this scenario. However, that post is nearly 3 years old and perhaps inaccurate. I'm hoping to get a second opinion and hopefully a work-around if this still a limitation in Salesforce.

2 Answers 2

1

Try this in a JS button:

var primary = sforce.connection.query("SELECT Id,ContactId FROM AccountContactRole WHERE AccountId = '{!Account.Id}' AND IsPrimary = True");
if (primary.size == 0) {
    var errorPlacement = document.getElementById("errorDiv_ep");
    errorPlacement.innerHTML = "You must specify a primary contact within Account Contact Roles before proceeding.";
    errorPlacement.style.display = "block";
} else {
    var ownerEmail = '';
    var ownerId = '{!Account.OwnerId}';
    var userId = sforce.connection.getUserInfo().userId;

    if (ownerId.toString().substr(0, 3) == "005") {
        ownerEmail = (sforce.connection.query("Select Id, Email FROM User WHERE Id = '{!Opportunity.OwnerId}'")).getArray('records');
    } else {
        ownerEmail = (sforce.connection.query("Select Id, Email FROM User WHERE Id = '" + userId + "'")).getArray('records');
    }

    var priName = primary.getArray('records');
    var templateId = (sforce.connection.query("select Id, Name FROM EmailTemplate WHERE DeveloperName LIKE '% XXXX DEVELOPER NAME XXXX %'")).getArray('records');
    var URL = '/_ui/core/email/author/EmailAuthor?&p2_lkid=' + priName[0].ContactId + '&p3_lkid={!Account.Id}&rtype=003&retURL=%2F{!Account.Id}&p26=' + ownerEmail[0].Email + '&template_id=' + templateId[0].Id + '';
    window.open(URL, '_self');
}

It will check the Account Contact Role Exists then SHOULD open the relevant email template with the contact already selected :)

2
  • Thanks Timothy, this gets me real close. The code doesn't run as posted but I can adapt this approach for my solution. Commented Jan 20, 2016 at 14:39
  • @SwisherSweet Glad I could help at least a little :)
    – Tim
    Commented Jan 20, 2016 at 14:50
0

Why don't you enforce the selection of a "Key Contact" on the Account, you can then remove all email buttons and have a custom button where you could check to make sure that the user has completed the Key Contact field prior to clicking the button?

Or you could use Account Contact Roles and ensure they have selected a role as primary prior to clicking the button

2
  • Thanks Timothy. I tried using the account role with a primary contact, and that did not filter nor default that contact when sending an email from account. Perhaps I'm doing something wrong? Commented Jan 20, 2016 at 13:55
  • Yeah you'll need to have a JS button do this or a VF page in the middle of your user clicking on the button and the Email being generated.
    – Tim
    Commented Jan 20, 2016 at 14:04

You must log in to answer this question.

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