So I want to essentially fake an EmailMessage SObject when a case is created. The case will have a subject, description, contact email, etc.

I want to replicate the behavior of an email-to-case (where you can easily reply to the email via SF's built-in messaging) but while receiving the cases as web-to-case.

Here's the logic I think I have to use:

trigger spoofEmailMessage on Case (insert) {
    //create EmailMessage SObject
    //insert description for message body, insert subject for subject, insert email address for email address
    //add to THIS case

Any help? Thanks!

  • Are you trying to spoof "Email to Case" or are you trying to create a response email without sending it? Its unclear to me as to what functionality it is that you're trying to "spoof". You could choose to use the new "Notes" feature if you want to add information to a Case. A process such as this should have a business purpose. You don't want to leave the impression to an auditor that you actually sent an email that was never sent.
    – crmprogdev
    Sep 29, 2015 at 14:01
  • Our support team enjoyed the ability to respond within Salesforce to a case when we were using email-to-case. We switched to web-to-case and wanted to see if we can keep that functionality of being able to respond within SF.
    – AKor
    Sep 29, 2015 at 14:08
  • Okay, but "who" are they responding to? Is the purpose to have a record of their response to someone within your support team that goes into the case record which either has been or will be conveyed to the customer via the web interface?
    – crmprogdev
    Sep 29, 2015 at 16:23
  • They're responding to whoever sent the case in. The purpose is to make it easier to respond instead of having to copy and paste the email address, etc.
    – AKor
    Sep 29, 2015 at 22:08
  • 1
    AKor -- you should read the Apex doc (and innumerable other web resources) on how to write triggers (you'll want an after insert trigger BTW) and then post more code -- this looks like you are asking us to do your work for you
    – cropredy
    Sep 30, 2015 at 22:20

1 Answer 1


There actually is an EmailMessage sObject that's intended for use with EmailToCase that you could potentially use. All of the other email messaging that you're familiar with are Apex Messaging Namespace Classes that don't have an sObject associated with them that's part of the API you can directly access. Instead there's the SingleEmailMessage() constructor along with the various class methods that set related properties, which I don't think is what you're looking for. So, if you want to "spoof" an object, the EmaiMessage sObject would be the one to spoof, especially since it supports cases.

  • we're thinking alike here -- I answered similar question from OP here: salesforce.stackexchange.com/questions/94071/…
    – cropredy
    Sep 30, 2015 at 22:18
  • Had I seen that, I'd have voted to close this one as a duplicate. Yes, we are in agreement here. I've been learning from you. ;) I think at the root of his issue is that he's not developed his business processes and related work flow when implementing web to case. But that's beyond the scope of what can fully be addressed here. This is more akin to putting a bandaid on it.
    – crmprogdev
    Oct 1, 2015 at 12:15

You must log in to answer this question.

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