Skip to main content

Building a Mobile App faster than it takes to make Coffee Using Salesforce1

The world is moving towards mobile, screens are getting smaller (and larger simultaneously). Cloud has already replaced the need for the computer as we know it and mobile has now stepped up to finish the job. To become a complete customer company we need to cater to every screen the customers prefer.

Now as a Force.com platform loyalist (and a purist at that) I find it really annoying that I have to learn a new language (Objective C for iOs and Java for android) just to build an mobile app. But this nagging piece of overwork is no longer a trouble. Have no fear Salesforce1 is here.

The moment Salesforce1 was announced, it is understood that it is a game-changer. Salesforce1 app is to mobile what visualforce did to cloud development, smash it. Generations ahead of its time, Salesforce1 is a treat to all visualforce developers out there to bring amazing functionality to phones. Before we begin, lets get few things clear.

1. Salesforce1 is a way of building mobile apps around Salesforce, using the existing Salesforce data, heroku and many other services. For full list of API's and Services included head over to Salesforce1 page. (Side note: Did you checkout the awesome new developer homepage? )

2. Salesforce1 is just an extension of existing Salesforce application, so you can migrate any existing Visualforce page to mobile. It does not support Cordova libraries yet but I am sure they will support that in the future. (Fingers Crossed) (Edit: Thanks to @Metadaddy you can get most thinks to work using pure HTML5, e.g. here is a great article that shows you how)

3. Salesforce1 is the most awesome platform that allows you to deploy Force.com applications on mobile faster than you make coffee.

Lets get started on building a small form based application that will collect responses from people in a conference. We will build a lead generation page using Visualforce and deploy it for Salesforce1 before you make coffee. So lets begin and don't forget to put that coffee pot boiling.

Step 1: Go to Setup -> App Setup -> Customize -> Leads -> Field Sets



Step 2: Create new Field Set adding the required fields. (Side note: If you are an Salesforce Admin and a Developer is trying to confuse you by using complex visualforce jargons whisper field sets in his ears to scare him. More on field sets here.)



Step 3: Create a Visualforce page called SurveyPage and use the Field set created in step 1. The following code adds a field set called Survey on the visualforce. Note: I am using Standard Visualforce controls, if you intend to add a custom CSS to your page please make sure you use Responsive Web design to cater for all Screens.

Visualforce code:

<apex:page standardcontroller="Lead">
<apex:form>
<apex:pageblock>
<apex:pageblocksection>
<apex:repeat value="{!$ObjectType.Lead.FieldSets.Survey}" var="f">
<apex:inputfield value="{!Lead[f]}">
</apex:inputfield></apex:repeat>
</apex:pageblocksection>
<apex:pageblockbuttons>
<apex:commandbutton action="{!Save}" value="Submit Survey">
</apex:commandbutton></apex:pageblockbuttons>
</apex:pageblock>
</apex:form>
</apex:page>


Step 4: To enable the visualforce for mobile we have to set the Available for Salesforce mobile apps flag on the edit page.  (Side note: If you are building the page using Development Mode or any IDE, go to Setup-> Develop->Pages to see that flag)


Step 5: Now we are all set, create a new Visualforce Tab called Survey and assign it to the visualforce page.


Step 6: Go to Administration Setup -> Mobile Navigation

Step 7: Add the Survey tab to the Mobile Navigation.
Step 8: Open Salesforce1 app on iOs device and test your page. (Side Note: One super cool feature about Salesforce1 is that if you do not have a Apple Device you can test your application one browser. Go to <Salesforce instance>/one/one.app)


Step 9: Enjoy your Coffee.

Compatibility issue:
Salesforce1 is available for all iOS devices and can be downloaded from App Store. For Android devices however the minimum requirement is Android 4.2 (Jellybean), all other devices will receive Chatter Mobile 3.4. I find it offensive to discuss Windows mobile OS.

Popular posts from this blog

The curious case of the custom redirection on Salesforce Console

Every developer worth their salt knows that the easiest way of redirection from a page to another is by using everyone's favorite function

public PageReference redirect() { PageReference pageRef = page.peskyProblemRedirection; pageRef.setRedirect(true); return pageRef; }
And the method is called by adding it to the Action attribute of the CommandButton or link, which works like charm and the user is redirected to the page after completion of the action.
So why am I going back to the basics? Because this way of redirection causes a pesky little problem in using the Service Cloud or Sales Cloud console.

Let's illustrate the problem, let's say you have a visualforce page as follows:

<apex:page sidebar="false" showHeader="false" controller="myExampleController"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!Redirect}&qu…

Some PDF tricks on Visualforce: Landscape, A4, page number and more

The beauty of Visualforce is simplicity. Remember the shock you received when you were told the entire page renders as PDF if you just add renderAs=PDF to the Page tag.

For those who thought I spoke alien language right now, here is the trick, to render a page as PDF, we add a simple attribute to the <apex: page> tag

<apex: page renderAs='pdf'> This will render the entire page as PDF.

Now, say we need to add some extra features to the PDF. Like a page number in the footer or we need to render the page in landscape mode. Faced with this problem, I put on my Indiana Jones hat and went hunting for it in the vast hay-sack of the internet (read: googled extensively). Imagine my happiness when i found a big big page with many big big examples to solve the problem. The document I am referring to is from W3C, paged Box media.

Long story short, I now possess the ultimate secret of rendering the page in any format I want. So here are few tricks I learned from the page. To p…

Cache me if you can: What you should know before daring to set URL parameter on visualforce

If someone gave me a pence for every time there was an SOQL query in an APEX Class without using Limit or a condition during a code review, I could afford a Lamborgini this month. Sigh. If only. We make it a habit of going digging for data, at the very moment we need it. The crux of this problem happens when you have chain classes which are independent of each other. Each class needs the reference from a single record and we have to query for that record every single time.

While we don't see it, every SOQL query has a cost to it, and it does not go in my Lamborghini fund, however, it should. In a recent project, we had to construct an Account 360 page that could fetch information from different integration points. The page was also called using a live telephony integration, which could pass the phone number for the account. This required an ability to keep in context the Account that was on call.

Passing the Account id in URL parameter was a valid option, however, any manipulatio…