Using Regex to Parse Text Fields

Regular Expressions always seems very complicated, but they can elegantly solve some complicated problems. I had an interesting problem where I needed to find some text that matched a pattern in a text field and pull it out. I ended up turning to using a regex matcher to find the information I needed.

The hardest part of regex is coming up with the correct pattern. One site that can help with this is This site lets you enter sample text and it gives you regular expressions matching certain parts of it.

In this example, I’m looking for a date that is prefixed by the text “Completion Date:”. My date will always be in the MM/DD/YYYY format, so my pattern is pretty simple. I declare a pattern and a matcher and then loop through all the matches and output them to the debug log.

String DATE_PATTERN = 'Completion Date:(\\d{1,2}/\\d{1,2}/\\d{4})';
Pattern p = Pattern.compile(DATE_PATTERN);
Matcher pm = p.matcher('Some text, more text. Completion Date:11/15/2012 even more' +
                         'text Completion Date:5/6/2012');
while (pm.find()) {

While this is a pretty simple example, it shows how you can avoid doing searches, finding indexes and performing substring operations in text fields.

More Chatter Mobile Features

While I’m still excited about Visualforce pages in Chatter Mobile, I was able to dive into more of the features in Chatter Mobile and they are great! Below you’ll find some details about other features I really like:

Compact Layouts are used in a number of places in Chatter Mobile. These include the detail page for a record and enhanced lookups (more on those next). You can have multiple compact layouts per object and assign them to different record types. To edit your compact layouts, navigate to Setup>Customize>Object>Compact Layouts. After creating a layout, make sure to assign it to a record type. The first place you’ll see the change is at the top of the detail page.

compact layout


You can then edit the page layout and add expanded layouts lookups to other objects. These add cards to the mobile view and use the same compact layout.

expanded lookups

The recent items for each object has several improvements. Notice the New button to allow you to create new records easily. List views you’ve used recently can be accessed from this page as well. These are displayed as cards that look similar to the compact layouts but the data in them is determined by the columns selected in the list view.

recent accounts


Finally, I also really like the integration with your phone’s calendar. Use the Today app in Chatter Mobile and it shows you all your meetings and if it matches up attendees with Salesforce contacts, you can see their contact details.

What are your digging about the latest version of Chatter Mobile? How will it help your users be more productive on the move?

Chatter Mobile and Visualforce

Salesforce’s mobile offering keeps getting stronger with the run up to Dreamforce. Last night the latest version of Chatter Mobile for iOS hit the app store and it sounds like the Android one is hot on its heels. It is chock full of features, but the one that caught my eye immediately was that we can now include Visualforce in the app.

First, we need a Visualforce page that is already mobile-ready. Fortunately, I already had some in my demo org thanks to Reid Carlberg’s Javascript Playground. Install the unmanaged package into a dev org and you’ll see it includes several VF pages that work well in mobile browsers. The one I’m going to use is the page called LABJS_JQueryMobile130_Hello.

After we have a page, we need to tell Salesforce that the page itself is mobile ready. That is easy to do by navigating to Develop>Pages, editing the page and checking the box “Available for Salesforce mobile apps”

mobile enabling a VF page

Now, we get to the good stuff. Under Administer>Mobile Administration, you’ll find a new option called Mobile Navigation. This lets us rearrange “stage left” in the Chatter Mobile app. We can add and remove standard components and also add our mobile enabled Visualforce tabs here.

mobile navigation


With everything in place, you should be able to open Chatter Mobile, see your tab in the stage left menu and select it:

stageleft  vftab

And that’s all there is to getting Visualforce pages in Chatter Mobile. Have fun hacking!

Update: In my original post, I had stated that you also need to mark the tab as mobile ready. That isn’t needed so the post has been updated.