Nov 29, 2012

Formula Example - Days Until Quarter's End

Today I bring you two ways to accomplish the same thing; display the number of calendar days until the end of the quarter. You probably wouldn't use these formulas to create a field (why show the number of days on every record?), but might use on a Visualforce page or email template. You may even modify them to enhance a validation or workflow rule.

The first way uses a series of nested IF() functions whereas the second way demonstrates how to arrive at that number using a CASE() function. The CASE way has a small work around in it, explained below.

Using nested IF functions:

Typically a CASE function follows this pattern: CASE(expression,​value1, result1, value2,​ result2,...,​ else_result) which leaves very little room for additional criteria. Expression is usually the field you will look at the value of, valueX will be the value to look for, and resultX will be the text to display if valueX and resultX match.

The issue we have is valueX will be any date between a given quarters start and end dates (displayed within the AND()s below). Nothing prevents us from giving an expression of "1" (aka TRUE) and then providing the values as IF statements that return 1 or 0. We just need to ensure that the datatypes compared match and the criteria doesn't overlap as the first to return 1 or TRUE ends our CASE function.

Using the Case function w/ workaround:

Nov 28, 2012

Salesforce Mobile SDK - Mobile Visualforce Page and the Connected App

This is part two of the Salesforce Mobile SDK Series.  Part one is here:  Salesforce Mobile SDK - Introduction

There's one common component between Android and iOS development when creating a hybrid app and that's the Visualforce page.  This ability to code it once and use it multiple places was repeatedly touted at Dreamforce '11 and '12.  This post will briefly go over the creation of such a page as well as the creation of a Connected App.

"Connected App" is an application that can connect to over Identity and Data APIs. Connected Apps use the standard OAuth 2.0 protocol to authenticate, provide Single Sign-On, and acquire access tokens for use with Salesforce APIs...  (read more)

1)  Our simple page will take advantage of a few external files, a .CSS file, and two .js  found in the CloudTunes sample included within the SalesforcemobileSDK-Samples package.  Grab the Static Resource named "cloudtunes_jQuery.resource" and it's accompanying meta.xml from here:

2)  Open Eclipse/ IDE and create a new project for your mobile Visualforce project

3)  Copy cloudtunes_jQuery.resource and cloudtunes_jQuery.resource-meta.xml into your project, creating the "staticresources" folder if needed:  ../Workspaces/ProjectFolder/Project/src/staticresources/

4)  Jump back over to your IDE, right-click on your "src" folder and click on "Refresh" to pick up the new files.

5)  Save the Static Resource to the server by right-clicking on your "src" folder within the project explorer, going to "" and clicking on "Save to Server."

6)  Now create a new Visualforce page by right-clicking on your project --> New -- > Visualforce Page.  Give it a name and click on the "Finish" button.

7)  Below is how I've structured my page.  Take note of the different div data-role's.  Although I'm only creating one Visualforce page, my final product will have four different "screens" (Main, About CRM Science, Ami, and Kirk).

Now that we have the page, it's time to create a "Connected App" within our Salesforce org.  Again, a "Connected App" is defined as an app that leverages the Identity and Data APIs to connect to Salesforce.  If you're familiar with "Remote Apps," Connected Apps are meant to be an updated replacement, including additional features giving you the power to limit who can use the app and which security policies are used by the app.  After the app is created, we'll also receive our Consumer Key and Secret values that are used when creating the hybrid app in Xcode or Eclipse.

Configuring a custom app is a straightforward process.  First you define the OAuth metadata with details like the app name, description, callback URL, operational IP range (optional), as well as info about enforceable mobile policies (also optional).

1)  Navigate to Setup -->  App Setup --> Create --> Apps and click on the "New" button within the "Connected Apps" section.

2)  Provide the "Basic Information" for your app.

3)  Next, define the details for the API Integration.  For the Callback URL, I've defined "testsfdc:///mobilesdk/detect/oauth/done" and selected the "Access your basic information" OAuth scope.

4)  Click on the "Save" button and you'll be taken to your new Connected App's record.  Notice the Version, Status, Consumer Key, and Consumer Secret fields.

Now you're ready to begin your hybrid app "development."  In the upcoming posts, you'll see how to configure your dev environments (Xcode or Eclipse) and how to use the Salesforce Mobile SDK to take advantage of the power of your Visualforce page.

Nov 21, 2012

Salesforce Mobile SDK - Introduction

It's hard to avoid the excitement that is being generated as a result of's mobile SDK. If you made the pilgrimage this September to Dreamforce in San Francisco or braved the rain at this month's Cloudforce in New York, you may have surely been exposed to the mobile SDK in one way or another. This year's Dreamforce App took advantage of the Salesforce Touch Platform. Several of the sessions at both events demonstrated just how easy it was to develop an app for both the Android and iOS platforms while minimizing the amount of code that had to be rewritten.

Using the Salesforce Touch Platform, you can develop apps in three ways - each has their own unique advantages and disadvantages.

Coding is specific to the platform, meaning your using the traditional development tools and languages used in iOS and Android development. This approach requires you to be well versed in Objective-C for iOS, Java for Android, and to be able to navigate their respective environments, Xcode and Eclipse. Once developed, these apps are packaged and made available on the platforms' app market places.

Using stadard web technologies, like HTML5, Javascript, and CSS, web pages are created to mimic the look and feel of native apps. However, these are not downloaded from the platforms' app market places, but are accessed via the mobile device's browser. Many of the device's native hardware functions are not accessible using this approach.

Using the hybrid approach, you can take advantage of the write-once-run-anywhere philosophy and wrap an HTML5 page (or Visualforce page) within a native app container while having access to a device's hardware capabilities, without needing to know Objective-C or Java.

Over a series of posts to follow, I will detail the creation of an HTML5 based Visualforce page and how to generate both an Android and iOS app, using the same page. These posts will also detail the steps required to setup both development environments.

Nov 20, 2012

Formula Example - Case Days Open

Today's Formula calculates either the number of days a case was open before being closed or the number of days the case has been open since it was created.

This formula uses 3 different functions:
  1. IF(logical_test, value_if_true, value_if_false) - Determines if expressions are true or false. Returns a given value if true and another value if false.
  2. ROUND(number, num_digits) - Returns the nearest number to a number you specify, constraining the new number by a specified number of digits.
  3. NOW() - Returns a date/time representing the current moment.

Here's a Case view that displays two cases, both open and closed, the fields referenced by the above formula and the formula field itself (# of Days Open).

Nov 12, 2012

Using Business Time to Set Workflow Task Due Date

A couple of weeks ago I posted a hack that enables assigning a workflow task to a related user on the triggering object. This works with a class called WorkflowInstructions that parses a task descriptions and looks for a familiar string format (a "workflow instruction"). Once a workflow instruction is found, the class processes the workflow task according to the instructions.

Since the code allows processing of several types of workflow instructions, here is another useful use case... setting activity cto a certain number of business days from the case create date. For some reason, business hours is available in apex, but not when setting workflow tasks.

So here is what you need to add to the previous post code sample:
  • Add a business hours variable to hold your selected business hours record.
  • add 'businesstime' when checking for workflow instructions.
  • add a method that processes the 'businesstime' workflow instruction.

You still need the code for the trigger as in the previous post: And now, all you have to do to make the workflow work is to set up the workflow instruction in the description of the workflow task. The trigger will fire, then change the task activity due date, and then remove the instruction from the description. here is an example:

Nov 6, 2012

Using Bucket Fields for Organized Reporting

Up until the Spring '12 release, if you wanted to categorize data within your reports, you had to create additional formula fields to do your classifications and then pull these new fields onto your report. With the advent of reporting buckets, you can easily categorize records within your reports on the fly, directly from the report builder screens.

For this example, let's say you have a set of Account records, each having the standard currency field "Annual Revenue" populated. For reporting purposes, you want to categorize your Account records into three different tiers.

Gold: Annual Revenue > 3,000,000
Silver: Annual Revenue between 1,000,000 and 3,000,000
Bronze: Annual Revenue below 1,000,000

Before buckets were introduced, you may have created a formula field that looks like this:

While this works, you've just created a field for this very specific purpose.

Bucketing can help you (and your non-admin employees) more efficiently do the same by following these steps:

1)  To create a new Bucket field, within a new/existing report, click on the "Add Bucket" link within the fields section.

2)  Next, specify a source field in the "Source Column," give your Bucket field a name, and define your ranges:

3)  Click on the "OK" button and you'll see your newly created "Service Level" field within your report grid:

Unfortunately, the current bucketing offering lacks the ability to create and use filters.

What if you had a client that has been with you from day one. Sounds like instant "Gold" level client criterion to me. It would be great to be able to include additional criteria, in this case something like "Initial Contract Date < 1/1/2005" = Gold, to the bucket calculations.

Additional Information: 
Bucketing in Reports:
Categorizing Data Quickly with Buckets: