Textexpander snippets for Apex

Last Updated on Saturday, 14 August 2010 07:19 Written by Steve Saturday, 14 August 2010 07:19

I just upgraded my work computer to Snow Leopard and one of the benefits I was most excited about was being able to update Textexpander, the incredibly handy snippet tool. You create short codes and when you type them they are replaced with pre-recorded text. They’re much better at describing what it does. It’s really handy for email signatures, canned content for technical support–really anything you ever type more than once.

With the new features Textexpander got really interesting for use in coding on the Force.com platform. The Force.com IDE doesn’t have code completion like the in-line code editor does, and it’s something I look forward to Salesforce.com providing. But in the meantime Textexpander is a great solution for helping you with code you write over and over again.

Textexpander now allows you to put variables in your snippets and allows you to fill those variables as you are expanding the snippet. So, for example, when you’re declaring a List of Accounts, you don’t have to type List twice, and Account twice. It’s really slick.

I’ve created a Snippet Group for common Apex syntax. To use the file, install Textexpander. Right click on the link to the Snippet Group and save to your computer. It’s an XML file, but you need to maintain the .textexpander extension on it. Then open up Textexpander and ‘Add Group from File.’ The group will show up in Textexpander.

Right now this Snippet Group includes:

  • declaration of lists, sets, and maps
  • declaration of an sObject
  • for loops, both kinds
  • if statements
  • select statements
  • test methods
  • try catch block
  • system.assert statements
  • describe result for an sObject
  • describe result for a field

It’s just a start, but if you take it and like it, add to it. Let me know and we’ll expand this Snippet Group to be comprehensive. Clearly there should be a VisualForce Sinppet Group as well. If you create one, please let me know!


4 Comments

  1. Jeff Douglas   |  Saturday, 14 August 2010 at 6:25 pm

    Awesome idea Steve! I’ve seen TextExpander but have never used it. I installed your snippets and they are magic! Hope someone produces a Visualforce group. I’m working on something similar… it’s a Chrome extension that gives you access to Salesforce docs. Particularly Apex classes, Visualforce components, and such.

  2. Steve   |  Saturday, 14 August 2010 at 8:00 pm

    Thanks Jeff! Textexpander is pretty amazing. I use it all day and now with the fill capability it’s crazy helpful.

  3. Joel Dietz   |  Monday, 16 August 2010 at 6:46 pm

    I’ve been compiling my own list over at Snipplr (http://bit.ly/ayKpxu) but since the Snippets (OS X) to Snipplr doesn’t transfer tags it isn’t easily sortable. A better solution would be much appreciated!

  4. Steve   |  Tuesday, 17 August 2010 at 7:23 am

    Try out textexpander and see if you like it better. I’ve been happy with it. Thanks for the link to your snippets!

Leave a Reply