6

I'm trying to figure out a way to add a list of contact email addresses to a case custom field anytime a case is created.

Use case: Specific accounts require other people to be emailed on any of the communication about the case. Example: a case was received by Acme and Jim, John, and Julie are required to be CC'd on the email communications from us to the person who opened the case. See screencast for walk through.

Question: I'm looking for a way declaratively to do this, however I think I'll have to resort to a trigger but just looking for other people opinions.

Current solution: create a workflow rule for every account which requires others to be emailed and run field updates on the case to insert those email addresses.

Screencast of the problem: http://screencast.com/t/5fVdfHTkwj1d

3
  • Great idea to add the screencast, conveys the context so quickly! – techtrekker Nov 1 '12 at 0:27
  • 1
    Thanks, I love the screencast just for this reason. If a picture is worth a 1,000 words then a screencast is worth Moby Dick ;) – Fifedog Nov 1 '12 at 0:38
  • Indeed nice, but one issue with screencast - if you want to keep some of the information hidden, it's harder to do when you capture a movie. I am not saying we are anonymous on the web (we are not if anyone asks) but still, Biz data is somewhat confidential usually. – Saariko Nov 1 '12 at 7:03
2

I would tackle this with a distribution list and custom field on the Account, if your corporate email system supports them.

  1. Create the distribution list, acme.cc@company.com. Put Jim, John and Jill on the list. This also adds the benefit of being able to replace recipients without changing code.

  2. Add the distribution list to a custom field on the on the Account, perhaps Account.People_to_cc__c.

  3. You cannot use a formula field on the Case to pull this address. It'd be something like Case.Contact_r.Account.People_to_cc__c.

1
  • I think I like this answer. Beside the DL which I'm not going to use, but the idea of just making a custom field on the Account as Text with those email addresses listed in that. From there I should be able to either put that list on the case or pull it from the account. This doesn't fit my original requirement, marking contacts, but it does fit the spirit of my request, give the business ability to control who get's CC'd. – Fifedog Nov 8 '12 at 1:21
0

(Disclaimer: this comes from a guy who was raised on S-Controls and can't help himself hacking some dirty JavaScript like that every once in a while)

Not a big fan of the trigger solution to be honest.

  1. what will you do if you need 5 CC addresses? Make 5 fields on the Case, last one unused except for handful of clients?
  2. Will you handle updates of contact's email address? And deletes of Contacts as well?
  3. Will you always remember to take out the email of guy that raised the case (would look stupid to send it to him as "To:" address and then repeat in "Additional To")?
  4. What if the count of characters will in future go over 255?

As mentioned by techtrekker - I'd go with URL hacking for the standard emailAuthor.jsp page (tons of search results like here or here) + JavaScript API to perform SOQL on the Contacts. From the screencast you're probably already familiar with emailAuthor.jsp.

Check if custom button with "Execute Javascript" behavior will work for you:

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

var contacts = sforce.connection.query("SELECT Email FROM Contact WHERE AccountId = '{!Account.Id}' AND Named_Support_Contact__c = 'Yes' AND Id != '{!'Case.ContactId}'"); // last AND is there because I believe you want to email Case Contact person but do not spam him/her with another copy of the email

alert(contacts); // for debugging purposes, feel free to do it properly with console.log() if you want and remove completely when you finished testing

var additionaCcAddresses = '';
if(contacts != null && contacts.records != null){
    for(var i=0, len = contacts.records.length; i < len; i++){
        additionalCcAddresses += contacts.records[i].Email + ';';
    }
}

var url = '/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=500&p2_lkid={!Case.ContactId}&p4=' + additionalCcAddresses;

// I'm skipping selection of email template etc - your screencast shows you already populate what you want.
window.open(url, 'newEmail');

Play with it, decide whether it looks too hacky (you might feel more confident with creation of VF page with action attribute that would craft similar url and redirect the user)...

0

Our solution for a similar issue, was that we created a new Custom object and a related list on the Case object - can be in a simple one that holds the contact's email - call it: 'Named_Contact__c'

Once your 'Named Contact' is checked, a trigger can/should create a new 'Named_Contact__c'.

The 'Named_Contact__c' is a related list to the case.

When you change the Yes/No button A trigger needs to remove that entry from the case.

When you click your custom send email button, you need to select all the emails from the related list.

Using this method You can have unlimited number of CC's on the case

Just need to keep those 2 triggers working.

0

I can't think of a declarative way to do this.

One alternative would be to write some javascript behind the custom Email Customer button, which uses the AJAX toolkit to retrieve the email ids of Contacts who are Named support representatives, and then pass them in as URL Query Parameters to the Email Page.

The only other plausible alternative seems a trigger on Contact, which stamps / removes the email addresses of Named Support Contacts on the Account. Once we are able to get these email address on the Account, you can use them reference them on the case as a Cross Object Formula Account.NamedSupportContacts__c

trigger ContactAfter on Contact (after insert, after update){

List<Id> accIds = new List<Id>{};

for(Contact con : trigger.new)
if(con.NamedSupportContact__c = 'Yes')
accIds.add(con.AccountId);

Map<Id, Account> accMap = new Map<Id, Account>([Select Id, NameSupportContacts__c]);

for(Contact con : trigger.new){
if(con.NamedSupportContact__c && (trigger.isInsert || trigger.isUpdate && trigger.oldMap.get(con.Id).NamedSupportContact__c == 'No'))
accMap.get(con.AccountId).NamedSupportContacts__c += ';' + con.Email;

if(!accMap.isEmpty())
Database.update (accMap.values());

}
}

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.