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
Attribution to: Fifedog
Possible Suggestion/Solution #1
I would tackle this with a distribution list and custom field on the Account, if your corporate email system supports them.
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.
Add the distribution list to a custom field on the on the Account, perhaps
Account.People_to_cc__c
.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
.
Attribution to: Mike Chale
Possible Suggestion/Solution #2
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());
}
}
Attribution to: techtrekker
Possible Suggestion/Solution #3
(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.
- what will you do if you need 5 CC addresses? Make 5 fields on the Case, last one unused except for handful of clients?
- Will you handle updates of contact's email address? And deletes of Contacts as well?
- 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")?
- 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)...
Attribution to: eyescream
Possible Suggestion/Solution #4
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.
Attribution to: Saariko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3952