I am trying to see if I can pull Contacts into a Case when it is created.  When a Case is created under a certain record type, I want to be able to pull in any Contacts marked as Primary that are associated with the Account that the Case is also associated to.  Does anyone know if this is possible and have any examples of how to do it?  I need this because I am also setting up a WFR Email alert to send to all the primary contacts for an Account. Thanks,

  • (1) What object will the email alert be written against? (2) Given (1), what specific Email Alert recipient field available in the multi-select picklist on the Email Alert specification page will you be using? – cropredy May 19 '16 at 16:30
  • @cropredy -- The email alert will actually be written off the Account object, because we need to group multiple Cases under 1 Account, which we are doing by substituting a Visualforce page as the email template. – J. Neilan May 19 '16 at 17:40
  • I have an idea (no code) but where is the information (what sobject) about whether a Contact is primary for that Account? Is it the Contact recordtype or a checkbox field on Contact? – cropredy May 19 '16 at 21:32
  • @cropredy -- The email is being sent from the Account. The trick is that there can be multiple Contacts marked as the "primary" as it's a custom field on the Contact record. I would like to be able to send the email to all those marked. – J. Neilan May 20 '16 at 15:41

Here's an approach:

  1. When the case is created with a certain record type, you need to signal a process builder flow on the parent Account. That will require a DML event on the parent Account. You can use Process Builder to do that - for example, by setting a field on Account called IsReadyToNotifyPrimaryContacts__c to true.
  2. A Process Flow on Account starts when IsReadyToNotifyPrimaryContacts__c is true. Its immediate action is to update field IsReadyToNotifyPrimaryContacts__c on all child Contacts. Note, same field name, different objects. After this field update, reset Account.IsReadyToNotifyPrimaryContacts__c to false.
  3. Another Process Builder Flow on Contact that triggers when Primary_Contact__c and IsReadyToNotifyPrimaryContacts__c are both true. Actions are to do the Email Alert (the template will have access to Contact fields and parent Account fields) as well as to reset Contact.IsReadyToNotifyPrimaryContacts__c to false.
  4. The same process builder flow on Contact as in #3 also handles the use case of Primary_Contact__c = false and IsReadyToNotifyPrimaryContacts__c = true with a simple immediate action to set Contact.IsReadyToNotifyPrimaryContacts__c to false.

Basically, the above is an elaborate no code way to go up from Case to Account and down to Contacts, signaling an Email Alert on Contact that can exploit the merge fields in both Contact and parent Account - as the emails go out to the Contact, not to the Account.

Now, if multiple cases for the same Account are created in the same transaction with the special snowflake recordtype it should still work - unless there is information about the Case itself you are communicating in the template, in which case the whole approach breaks down even for the singleton use case. This is because the email template won't be able to access the Contact, its parent Account, and some child case. Should this be the real use case - then you'll need a trigger on Case and Apex to construct the email to the various contacts

  • Thanks. Unfortunately, your last scenario is what exists for me. I have a WFR set up that is set up on a time-based event on the Account object. When the rule fires, I want an email alert to go out to any Contact records associated to the Account that have a custom checkbox field checked off. My email template is a Visualforce page, which loops through any Cases on the Account and pulls information from them to the email template. I need to be able to send the email alert, jus to Contacts marked with a custom checkbox field on that Account. – J. Neilan May 23 '16 at 18:51
  • @J.Neilan -- then, when the time event on the Account goes off, you'll need a field update on Account that signals a trigger that in turn constructs the email to: list in apex and uses a VF email template+component to render the contents. The ugly alternative is to maintain a list of 10, 20, ?? custom fields of type email on Account that contain the primary contact emails. – cropredy May 23 '16 at 19:00
  • Yes, I thought about the custom fields, and that could get crazy. Do you know where I can find sample code for a trigger like that? – J. Neilan May 23 '16 at 19:15
  • @J.Neilan My suggestion is to use DLRS to rollup the Contact emails into a delimited text field on Account then a simple trigger that uses the String split method to create a list of emails that you can use to populate the Email00__c, Email01__c, ... fields. DLRS will take care of contact insert, update, delete as well as any deltas on primary__c field or change in email address. – cropredy May 23 '16 at 19:29

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.