It’s a scenario many of us have been through.  You’ve slaved over your application for months, written impeccable tests, and verified everything works, but customers still can’t install the application because of test failures resulting from their validation rules and triggers preventing your test data from being created.  Even worse, you get a 1 star rating as they vent their frustrations.

For Chatter Unfollow Rules v2.0, I came up with a different approach to avoid this issue.  The app uses dynamic SOQL to let you pick which object, field, and criteria, similar to workflow rules, and then unfollows the records that match the criteria.  Since it works for any object and custom object, I realized I no longer had to be shackled to standard objects for test data and created a custom object for all of my tests, with custom fields for each of the field types supported by my app.  Even better, for Aloha apps, the objects don’t count towards app limits, so there’s no downside to the additional object.

I then had an easy way to make test data that would verify the app works as expected, and customers were able to install without issues.  An added side benefit is that patch upgrades now succeed for everyone as well, so I can push bug fixes without agonizing over whether to ignore apex test failures, because there aren’t any!

If you want to see the approach in more detail, check out the app here and open the UnfollowTests class:
Chatter Unfollow Rules – Unmanaged

Utility method for creating dummy test data:

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS