Yes, I get it; I'm a geek. After discovering Spring '10's support of Generic SObject Lists, I've been itching to try them out (I can just see my wife looking at me now wondering what planet I'm from). This afternoon, while working on some Chatter apps, I found a perfect use for them: Testing EntitySubscriptions (subscribers to records, objects and people) in Chatter.

There has been a lot of discussion inside the Chatter Dev ZOne around how testing Chatter apps may be different from testing other apps on the platform. One of the big areas we are finding is that data volumes can grow exponentially as more and more people connect with colleagues, and follow records. The result is that the need to write your code to run efficiently within the Governor limits is more important than ever. (You should always test and code against the Governor limits, of course, Chatter just emphasizes the importance of writing efficient code)

 The side effect of exponential growth of information with Chatter apps is that you need to write test cases that inject sufficient amounts of data to effectively test for large data sets. Reid gave some good examples on testing lessons learned and I am writing a series of Chatlets–white-labeled Chatter components that you can drop into your code and build your own apps—for CodeShare which will include a bunch of Chatter test helper methods, but the geek in me couldn't wait when I took Generic SObject Lists for a spin.

The code snippet below uses a List<SObject>, introduced in Spring '10. This new feature allows me to pass in any type of Object such as an Account, Opportunity, or Custom Object, and have a particular User follow them. Without the ability to create a generic List<SObject> I would have been forced to write a series of followEntitiesFor[Object Type] methods to achieve what I can now do in 5 lines of code. 

As you can see from the code above, the code is clean ,efficient, very handy, and also easy to test (btw, the ChatterTestHelper referenced in the snippet below will be in CodeShare in the next few days):


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

Add to Slack Subscribe to RSS