+ Start a Discussion

Issues updating the "IsExternallyVisible" flag on EmailMessage

As described here: https://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_service_emails_case_feed.htm ,
it should be possible to control the value of the "IsExternallyVisible" flag through a trigger.

We have our own logic which works well and were executing this code in the "before insert" of an EmailMessage record.
We recently noticed that even while our code sets the value in the before insert, Salesforce overrides this value later. (between the before insert and after insert)...

To fix this, I moved the code to update this field to the "after insert" logic.
But doing so, we now get an error when trying to update the EmailMessage records "Invalid operation".
I don't re-use the records comming from the Trigger.isNew cause that would cause "read only" exceptions.
What I do is like this:
EmailMessage emailToUpdate = new EmailMessage();
emailToUpdate.Id = mId;
emailToUpdate.IsExternallyVisible = value;
So I'm sure I'm only updating the IsExternallyVisible flag and not any other field that I wouldn't be allowed to...
I used this code already in execute anonymous mode to fix some emails incorrectly flagged as externally visible and this works from there.

What am I missing? Why doesn't there seem to be a proper way to control the IsExternallyVisible flag through code / trigger?...
Jamie BrowningJamie Browning

Why has no one answered this.


Come on Salesforce get your act together

Jamie BrowningJamie Browning

There is seemingly a Work around (Use Future Method), which in my experience also does not work either.

The documentation around all of this Case Feed stuff is terrible.


A Before Insert Trigger SHOULD WORK (but doesn't  thanks Salesforce),  If an After Trigger is used the record id should be passed to a future method to update the records.

So the issue here was incorrect usage of an update during an after trigger.


That said I have tried other solutions and it looks like Salesforce have stuffed this up royally.

Tina PadwickTina Padwick
Do you have Draft Emails enabled? We have discovered if you disable Draft Emails, the IsExternallyVisible flag seems to behave. The draft emails keep saving and depending on when you send the email the flag could be either set or not, very flakey behaviour.