0

Question

We have a formula field that determines the correct From Email address on a Case based on a field on the related Contact and the Case Record Type. We've reached the character limit on the formula field after several rounds of optimization and it must be replaced.

My first instinct is to use Apex against Custom Metadata but this will require a trigger on both Case and Contact to ensure that a change to the source field on either record will result in the correct calculation. This seems inefficient.

Is it more efficient to do it with a Visualforce page to replace all the Layouts? Can you combine the use of Apex:detail with a controller to calculate the email so that maintenance of the pages can still be done from a standard Layout? What do you lose control of when you switch to using apex:detail?

Context

We use the Quick Action Send Email for outbound messages from Cases and predefine the From Email field value based on a Formula Field currently.

A psuedocode example of the currently Formula is:

IF(  RecordType.Name = "Career Services Case" ),  CASE(
Contact.Specialization__c , 
"abc-def","careerservices@someuniqueURL.com",
"ghi-jkl","careerservices@someotheruniqueURL.net", etc.

There are 5 Record Types and over 60 specializations currently and we need it to scale to 100s of specializations, so we know that ultimately Formula Fields will not work.

Because the Send Email Quick Action automatically populates predefined field values on page load, there is no way (as far as I know) to trigger a check whether the parent Contact field (Specialization__c) has changed. Formula fields have the advantage that they do update on page load so they have worked well.

  • Can you provide a formula? – o-lexi Sep 25 '17 at 19:18
  • Can you share your formula field. So far, in the Case object, ContactEmail formula already exists. – Santanu Boral Sep 25 '17 at 19:18
  • Formula and context added for clarity. – AlwaysThinkin Sep 26 '17 at 14:07
2

Don't go VF page route unless you need something really special. Huge lesson learned is that the more you go native (do what you can with workflows, triggers etc rather than custom UI), the easier it is to eventually switch to Lightning Experience. If the "correct email" will be visible only in UI, how do you hope to send correct workflow email alerts or messages from apex batch jobs...

There are several official tricks to stretch a formula just a little bit more, you sure you've exhaused all options? Post it here, try us ;)

You could cut the formula into chunks, save the intermediate result in a text field populated with workflow for example, then reuse this field.

You could have a field on Case that contains copy of that parent field on Contact. You don't need a trigger to keep them in sync to cascade down to all Cases, you could achieve similar result with Process Builder. (of course it'll count as update so might change times on cases, reopen them if you have such logic, maybe fail to update if you have validation rules...)


Edit

"Send Email quick action" you say... So it's something available only in Lightning Experience, right?

  1. Would you consider splitting the functionality into 5 actions, one per record type? That should split the formula nicely. Just pay attention which one ends up on which page layout.
  2. Are you using the (refreshed to look Lightning-ish) Service Cloud console? There's a functionality called Macros that might help here. You might have to pay for the console licenses though if you don't have them already. Never hurts to ask!
  3. Maybe, maybe this could be kept almost pure configuration by using Flows / interviews. The stuff configured in Flash-based editor. I haven't used them to that extent but might be worth trying.
  4. Trigger / process builder as I've mentioned before the edit to cascade the changes down to related Cases...
  5. Have 1 Email / Text field on Contact per Case type, populate them with a Workflow whenever Specialization changes, select correct one in your simplified formula. Bit messy (each new rec type = new field and some mass data fix needed) but could work. Has to be workflow / process builder otherwise the size of final compiled formula will still depend on size of Contact-level formulas.
  6. Last but not least - developer could build for you Lightning component / VF page for email sending, with the required mapping. Not too hot on having to recreate whole functionality of email editor but it's a solution too. Hardcore version would be something that creates draft email with proper "From", saves it (yes, you can save drafts) and somehow redirects the user to finish writing it using all the standard features.

P.S. Don't use RecordType.Name in your logic. If you ever enable Translation Workbench somebody might translate it to French, German etc and logic will fail. Use RecordType.DeveloperName.

| improve this answer | |
  • Thanks @eyescream, I agree about the preference for native UI. The use case all hinges on automatically providing the support user the correct From Email so that they do not have to analyze a list of 100s of Org Wide Email Addresses when replying to a customer by email. It's largely a branding issue. – AlwaysThinkin Sep 26 '17 at 14:10
  • You really are the boss of thorough answers! 1. We actually already are splitting the formulas between multiple Formula Fields and relating each field to a distinct JavaScript button (so totally not LEX-ready). 2. That's an interesting idea about Macros, I haven't really explored them yet but since we are already Console users, that possibility is there. 3. Same with FLow Interviews although IIRC that would add extra steps beyond Click Send Email, Write Email, Send Email. – AlwaysThinkin Sep 26 '17 at 15:40
  • 4. Triggers, while inefficient are my go-to and with proper care I can make it reasonably efficient (although the thought that a change to Contact necessitates updating many Cases is disturbing since VRs could be violated). – AlwaysThinkin Sep 26 '17 at 15:42
  • 5. Pretty similar to what we're doing now, one formula field per Record Type. Becomes very challenging to check for accuracy. – AlwaysThinkin Sep 26 '17 at 15:43
  • 6. Agree that Vf page could solve it but again, breaks a very simple Send Email process into a more complicated one. – AlwaysThinkin Sep 26 '17 at 15:44

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.