2

I'm facing an interesting scenario. Spring 15 introduced the ability to "moderate" Chatter private messages. Basically, we can now create triggers on the ChatterMessage object. I coded a trigger and works like a charm.

However, we cannot create/INSERT ChatterMessage records from Apex code. This isn't an issue when it comes to implementing the trigger, but you cannot do the test coverage (not even 1% ?) of the trigger.

Thus, the trigger cannot be included on a Managed package. When I try to upload a Beta version of a Managed package, it throws the error:

Upload Failed: One or more Apex triggers lack test coverage.

So my questions are:

  1. Is there any way to add (at least a 1% of) test coverage for a trigger defined on a non-insertable (and thus non-deletable, non-updatable) object?
  2. Is there any way I can add a trigger defined on the ChatterMessage record (after insert) to a Managed package, and then upload package?
  3. How do people deploy a trigger of this sort on a production org?

I'm stuck :-) Ideas? Hacks?

Thanks in advance,

Antonio

  • 3
    I honestly haven't tried this, but it might work. Can your test code use the Connect API to create a ChatterMessage using the sendMessage() method? I'm thinking that will cause the trigger to fire. – ArtieBrosius May 8 '15 at 13:57
0

As suggested by ArtieBrosius, using the sendMessage() method from the Connect API will insert a ChatterMessage record and fire the trigger.

NOTE: When using the sendMessage() method, you cannot pass the Id of the "context user" (SFDC User executing the code) as recipient for the message. So if using this method from within a test method, we have to create a new User, and send the message to this User.

Thanks ArtieBrosius!

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.