Dec 19, 2012

Salesforce to Fix Issue With Oauth 2.0 User-Pass Flow

We recently hit an issue with one of our clients where an external service was trying to authenticate against Salesforce with oauth 2.0 user-pass flow but kept receiving "unknown_error.retry your request" from Salesforce. We searched online and used #askforce but the only fix we found was to loging using the Salesforce instance, which does not work for us as we are trying to access Apex REST in a managed package that will be available on the AppExchange sometime soon.

So we opened a case through the partner portal which was quickly confirmed and escalated. Within a week, we receive a response that Tier 3 have identified the issue and that R&D is working on a patch that will likely to be released today (19th Dec 2012). They did not elaborate much further even though we prodded for some more geeky details, except to say that "the issue was due to internal issue" and that "the patch will be released on all instances".

Kudos to Salesforce for a quick turnaround!

Dec 18, 2012

Formula: Ref Tag for Email-to-Case


If you're using Salesforce for customer service, chances are that you are using email from the Case object.  When you leverage the "Email-to-Case" feature, Salesforce will add to Case related emails a "ref:" tag.



Let's assume help@yourCompany.com is configured as your company's email-to-case Routing Address.  A customer needs assistance with one of your products and sends off an email requesting assistance.



This tag is what allows Salesforce to automatically connect this email to the appropriate existing case.  If not found, a new Case is created and set up in accordance with the configuration of that Routing Address.



So when the customer sends the email above, requesting assistance from help@yourCompany.com, you're email server or email client will be configured to forward messages sent to help@yourCompany.com to the Salesforce assigned email address, which looks like this:



When the email address is forwarded to the Salesforce address highlighted above, the Salesforce email services look at the subject and body of the message for an existing "ref:" tag.  If one is found, the email is created as Activity History for the associated case.  If one isn't found, it looks at the configuration of the help@yourCompany.com Routing Address and creates a case.  This is why it is important to not remove the tag from your emails; doing so could result in duplicate or unnecessary cases.



There may be scenarios where you need to know what the "ref:" tag for a Case is.  You might need to include this on e-mail templates for internally created cases for customers.  

How is this value constructed and what is the Salesforce Email-to-Case email service expecting?

If you take a look at a "ref:" tag, you'll see it follows this pattern:

To replicate this in a formula field, you can use this:


I've seen a similar formula on the forums, but I've added a LEFT($Organization.Id,15).  Without this, I was generating the first portion of the "Ref:" tag using the 18 character ID of my org.  The resulting "Ref:" tag did not match the "Ref:" tag from the email I received in prior testing.

Now you can use the new formula field on your Salesforce templates.  Alternately, you can follow this patter when developing your own Salesforce email handling services.

Dec 11, 2012

Formula Example - What Day of the Week is/was it?

I found a post over at the Apex Code board at DeveloperForce.com from someone who needed assistance creating a formula to determine how many Fridays occurred between two given dates.

Easy enough, I thought.  I'll just use a date method w/in a loop and count how many times Friday occurs.  I didn't find any date methods or dateTime methods that return the day of the week.  It seems like such a basic need; perhaps I glazed over it.

A quick Googlin' led me to one example, nearly 100 lines long.  It shouldn't be that difficult; I'd rather spend 100 lines showing you how to do the math and then 1 line of code using that math.

A little more poking around and this is what I found:

a = (x - y) (mod 7)

a = Day of the week index
x = a date in which you know the day of the week
y = the date in which you want to know which day of the week it was or will be

In a nutshell, figure out the number of days between your two dates (x and y), divide that number by 7, and the remainder (mod 7) will tell you the day of the week, based off of the known day of x.

We still need "x" - the copious amounts of calendar generators on the web all agree that 1/1/1900 was a Monday.  

Let's see it in practice, using 12/11/2012 as an example or proof (just pretend you don't know it's Tuesday).  12/11/2012 will serve as our "y" variable.

a = (12/11/2012 - 1/1/1900) (mod 7)
a = 41,252 (mod 7)
a = 41,252 divided by 7 leaves a remainder of 1
a = 1

Since we know 1/1/1900 was a Monday, we know that 1/2/1900 was a Tuesday, 1/3/1900 a Wednesday and so on all the way up to 1/8 when everyone has a case of the Monday's again.  There are 7 days between 1/8 and 1/1 and dividing 7 by 7 leaves you with a remainder of 0.  0 will represent Monday.  1/9/12 is a Tuesday and there are 8 days between 1/9 and 1/1.  Dividing 8 by 7 leaves you with a remainder of 1.  1 represents Tuesday.  The same logic tells you 2 is Wednesday, 3 is Thursday, 4 is Friday, 5 is Saturday, and 6 is Sunday.  In the example above, a = 1, therefore 12/11/2012 must fall on a Tuesday.

So all we need to do now is plug in our dates and use a few methods that do exist.

We'll use:
math.mod()
date.daysBetween()



Go ahead, try executing that code and seeing what the debug output tells you.

So now we have an easy mechanism for determining the day of the week for a given date. Let's go the extra mile and see how we can easily create a bit of code now that determines how many how many of a certain day occurred between two dates.



Dec 6, 2012

Salesforce Mobile SDK - Xcode Setup and iOS App

This is part three of the Salesforce Mobile SDK Series.  Have you read parts one and two yet?

  1. Salesforce Mobile SDK - Introduction
  2. Salesforce Mobile SDK - Mobile Visualforce Page and the Connected App

So far we've learned the differences between native, hybird, and HTML5 apps, how to create a mobile Visualforce page, and how to create a Connected App to get our crucial Consumer Key and Secret.  The next step takes what you've done and turns it into a mobile app.  By the end of this post, you'll have an iOS app that handles authentication and delivers a multipage experience.

Before you get started working with the Salesforce Mobile SDK, you'll need to set up your Mac environment.

1)  Boot up your Mac and install Xcode from the App Store.



2)  While that's downloading (it'll take a while), download and install GitHub:  http://mac.github.com/

3)  Pull in a local copy of the SalesforceMobileSDK-iOS project by using the "Clone in Mac" button here: https://github.com/forcedotcom/SalesforceMobileSDK-iOS



4)  While you're waiting, you'll want to clone the MobileComponents as well: https://github.com/forcedotcom/MobileComponents

5)  Launch a Terminal window (Finder --> Applications --> Utilities --. Terminal) and navigate to the cloned SalesforceMobileSDK-iOS folder, presumably in your home directory.  
  • cd ~/SalesforceMobileSDK-iOS
  • sudo ./install.sh
  • sudo cd ..
  • sudo chown -R YourUserName SalesforceMobileSDK-iOS
6)  By now, Xcode should have downloaded and installed.  If not, wait for that to happen, then launch it (Finder --> Applications --> Xcode).

7)  If you've never launched Xcode before, you'll land on this screen.  Click on "Create a new Xcode project" if prompted and if not, click on File --> New --> Project...



8)  From the menu, choose iOS --> Application, highlight the "Hybrid Force.com App" icon, and then click on the "Next" button



9)  Provide the following details about your new app and then click on the "Next" button.  You can get the "Consumer Key" and the "Redirect URL" from within your Salesforce org by clicking on the "Setup" link and navigating to Create --> Apps --> Your Connected App Name.  For more details on creating the "Connected App," see part two of this series.



10)  You'll now be prompted to choose a location to save your project file.  Navigate to your location of choice and click on the "Create" button.

11)  Once your project is created, highlight the "WWW" folder, right-click on it, and choose "Delete." 



12)  When prompted, click on the "References Only" button.



13)  Highlight your root project folder, right-click, and choose "Add Files to "Your Project"..."



14)  Navigate to your project directory, highlight the "WWW" folder, and then click on the "Add" button.


15)  Expand the "WWW" folder in your project browser and click on bootconfig.js.


16)  Find the line that begins with "var startData..."  This tells the application which page to load after authentication.  



Since we are building a hybrid app, we'll comment out the first line, uncomment the second line, and modify the path portion to reference the Visualforce page we created in part two of this series.



17)  Now it's time to make sure the app runs.  Make sure all of your changes have been saved, and then click on Product --> Run.  This will start up either an iPad or iPhone simulator and with any luck, request your Salesforce credentials:



18)  Enter your credentials and click on the "Login" button.  The app will then prompt you to provide permissions.  Click on the "Allow" button to continue.


After clicking on the "Allow" button, you'll see your mobile VF page.  If you tap/click around, you'll notice the interface and page navigation looks and feels like a native app.


In the next and final post of this series, you'll learn how to set up your Eclipse environment and use the the same Visualforce Page and Connected App to create an Android app.




Dec 4, 2012

iPad-less Salesforce Touch Testing

Salesforce Touch became generally available in the Winter '13 release.  It is available in the Contact Manager, Group, Professional, Enterprise, Unlimited, and Developer Editions and according to the requirements, currently supports Apple iPads (2nd and 3rd generation) with iOS version 5 and up.

Requirements:  http://www.salesforce.com/docs/en/touch_faq_tablet/touch_faq_tablet_reqs.htm

Unfortunately, not everyone has an iPad to access, test out, or even debug the new Touch interface.  Fear not, a simple change in your browser settings will allow you nearly the same access.

First, make sure that you have the new "Touch" feature enabled for your org and the users that you want to test with.

1)  Log into Salesforce and access the "Setup" menu:



2)  Under "Administration Setup," expand "Mobile Administration," "Salesforce Touch" and then click on "Settings:"



3)  Ensure that the "Enable the Salesforce Touch mobile browser app" setting is enabled



4)  Next, ensure that Touch is enabled for the user account you are testing with by expanding "Manage Users" under "Administration Setup" and clicking on "Users:"



5)  Find the relevant user(s) and ensure that "Touch User" is enabled:


Now that "Touch" is enabled in all of the right places, it's time to change your browser's user agent, effectively allowing your browser to mimic Safari.  Here's how to do that in Chrome.

1)  Log out and change your URL to "login.salesforce.com"



2)  Click on Chrome's "Settings" button and navigate to Tools -> Developer Tools (Shift+CTRL+I)

3)  Click on the Developer Tools settings button (the gear icon) in the bottom-right hand corner



4)  Click on the "Overrides" tab




5)  Ensure that "User Agent" is checked and choose one of the "iPad --iOS" profiles




6)  Refresh your Salesforce Login window and it should now look like this:



If you're familiar with the Salesforce Mobile SDK, this will look familiar to you.

Take note that if you are logging in with an account with an Administrator profile, you will not experience the Salesforce Touch interface after logging in, but will rather be redirected to the normal "Setup" page.

If anyone has a one of those new, shiny, touchscreen Windows 8 machines, I'd love to hear if the interface is "Touchable."

Not using Chrome?  Here's a link that may include information on how to change your user-agent setting w/in your browser of choice.