Friday, July 29, 2011

Efficient Regex Pattern for Getting Hashtags

After digging around the Internet for a while and not finding a regex pattern that was able to produce all of the hashtags in a String, I finally created my own based on information I gathered from a few other places.

\B#[a-zA-Z][a-zA-Z0-9]+

My sources include the following:

I took this information and created a method in Salesforce to grab all of the hashtags from a String and return it in a Set, as shown below.

/**
 * Get the Set of hashtags (including
 * the '#' character) used within a String in
 * all lower case, for ease of comparison.
 *
 * @param  text The String text to analyze.
 * @return      The Set of hashtags
 *              used within the text.
 */
public static Set getHashtagSet(
        String text) {
    
    // Instantiate the resulting set.
    
    Set hashtagSet = new Set();
    
    // Only look for hashtags if text is given.
    
    if (text != null) {
        Pattern hashtagPattern = Pattern.compile(
                '\\B#[a-zA-Z][a-zA-Z0-9]+');
        Matcher hashtagMatcher =
                hashtagPattern.matcher(text);
        
        while (hashtagMatcher.find()) {
            hashtagSet.add(
                hashtagMatcher.group().toLowerCase());
        }   // while (hashtagMatcher.find())
    }   // if (text != null)
    
    // Return the results.
    
    System.debug('hashtagSet = ' + hashtagSet);
    
    return hashtagSet;
}   // public Set getHashtagSet(String)

Tuesday, July 19, 2011

Navigation Extension for Salesforce Sites

Thinking about how to best handle navigation within Salesforce Sites, I decided to try my luck with setting up an easily re-usable extension that can be applied to an entire site.

Fortunately, it looks like the apex:commandLink element paired with apex:param is able to produce the customizable navigation code I wanted.

Instead of writing out methods like the following...

public PageReference goToPage1() { ... }
public PageReference goToPage2() { ... }
public PageReference goToPage3() { ... }

all that's needed is...

public PageReference goToDestinationPage() { ... }

Much better, right? See the demo source code for more details.

Monday, July 18, 2011

Preview as Admin Feature for Salesforce Sites

I just discovered (1 year too late) the Preview as Admin feature for developing Salesforce Sites.  This has got to be one of the more useful things that I wish I had picked up earlier.

Basically, when developing a site and testing it as an anonymous user, error messages are sometimes hidden behind the annoying "Authorization Required" message.

Preview as Admin saves the day by delivering the anonymous user experience, enhanced with a useful description of the errors at the bottom of the page whenever errors appear.

Awesome, indeed.  I wonder what other features are out there that I don't know but should know...

Friday, July 15, 2011

Settings to Produce YouTube-compatible Video with Expression Encoder 4

After some fiddling around, I figured out some simple settings that can be used to produce a YouTube-compatible video captured with Expression Encoder 4 Screen Capture and encoded with Expression Encoder 4.

Note: I started with the "VC-1 High Speed Broadband CBR" preset.

Video settings:

  • Mode = "CBR - 1 pass"
  • Bitrate = 1024 Kbps
  • VC-1 Settings...
    • Video Complexity = "Fastest (0)"
Audio settings:
  • Mode = "CBR - 1 pass"
  • Bitrate = "32 kbps"

Lead and Contact Merge Fields in Email Templates

Interesting note about Lead and Contact merge fields in Salesforce email templates: Some of the fields will populate regardless of whether the record is of the correct type.

For example, in my template, the first line read:
Dear {!Contact.FirstName}{!Lead.FirstName},

I figured that only one of the two fields would actually produce the target's first name. However, when I actually tested the merge fields in Salesforce with a Contact record and with a Lead record, in both instances the result read:
Dear JohnJohn,

Interestingly, this duplicate merge did not occur in the signature, where I had the following:
Sincerely,
{!Contact.OwnerFullName}{!Lead.OwnerFullName}

In the signature, only the relevant OwnerFullName field was populated, depending on whether a Contact or a Lead was selected.

I wonder whether this phenomenon is intentional or indicative of a bug...

Where Are My Packages?

After a ridiculously lengthy search on the Internet for guidance on finding the location of packages installed with apt-get, I finally stumbled on the solution: "See Where a Package is Installed on Ubuntu".

Basically, the command I needed was:
dpkg -L packagename