Data three ways from…

Over the past couple of months there has been a lot of chatter about some new ways to access your data. The REST API was released earlier this year as well as something called JavaScript remoting that is in developer release. I currently use standard Apex and Visualforce when creating custom apps on the platform so I thought I would take some time to better understand the REST API and JavaScript remoting.

I had a fun night playing with the code samples provided by Salesforce and thought I would share some examples. Below are three different ways you could access your data on the platform. My goal was very simple…query Salesforce for a list of accounts and display them in a table. Not earth shattering at all but hopefully the simple use case will illustrate three different approaches. Each approach will output a data table exactly like this:

Recipe 1: Using standard Visualforce page with Apex class

The first approach I took was to use an Apex class to query the data and then use a Visualforce page to display it. This is pretty standard development and should look familiar.

Here is the Apex class:
public with sharing class dataTableOne {

 public List getAccounts() {
  List accountsForPage = [Select Id,Name,Phone From Account Limit 10];
  return accountsForPage;

Here is the Visualforce page:

Data retrieved using standard APEX/Visualforce
Account Name Account Id

Recipe 2: Using JavaScript Remoting

When I first saw Josh Birk (@joshbirk) demo JavaScript Remoting at the Minneapolis user group meeting my reaction was, “That looks a lot like those old s-controls we use to write before APEX/Visualforce”. After he talked me off the ledge I got a better understanding of what situations you might use remoting (mobile dev, no viewstate, etc). I used his blog post here to build my recipe below.

Here is the Apex class:
global class dataTableTwo {

    global static Account[] findAccounts() {
        Account[] accountsForPage = [Select Id,Name,Phone From Account Limit 10];
        return accountsForPage;


Here is the Visualforce page:

Data retrieved via JavaScript Remoting

Data retrieved via JavaScript Remoting

Recipe 3: Using the REST API and JavaScript toolkit

The last recipe uses the REST API to access the data from Salesforce and has no APEX class. I leaned heavily on Pat Patterson’s (@metaDaddy) blog post and the JavaScript toolkit he created. Thanks Pat! You can see below that once you include his toolkit as a static resource it is just a few lines of code to query data.

Here is the Visualforce page:

Data was retrieved via REST API

Hope this was helpful. Love to hear any questions or feedback.

The ABCs (I need x and y) of development…

A while ago I saw this blog post, “The ABCs of Web Development” by Siddharth. I enjoyed it so much I thought it might be fun to try to do the same thing with development. A draft has been sitting in Evernote for a couple weeks now and I only needed X and Y (XML seemed too easy) to complete. So I decided to put out my incomplete list and see if anyone had an X, Y or any other concepts/terms they might stick in here. I will update and give you credit if you send me one.

Below is what I have so far. I'd love to hear your thoughts or additions!

APEX - APEX is a programming language created by that is hosted and run entirely on the platform.

API - API stands for "Application Programming Interface". Think of it as a set of predefined methods you can call to interact with your instance. 

Batch APEX - What you use to create large, complex, long-running jobs on the platform.


Custom Object - A custom object is pretty much the same thing as a database table. They can be defined through the declarative UI to extend your Salesforce data and have a number of field types you can add to them. 

DML - DML stands for "data manipulation language". This is basically all the different things you can do to modify your data in Salesforce (insert, update, delete, etc.). (Submitted by @knhornt) - " is the world’s first enterprise database built for the cloud. It's open, proven and trusted. is built to power the next generation of Cloud 2 social and mobile enterprise apps." Definition from the website. This new Salesforce offering was announced at Dreamforce 2010.

Data Loader (Submitted by @ashoknaglikar) - Desktop tool that allows you to easily access your Salesforce data.

Eclipse - Eclipse is an open source IDE in which you can develop your APEX and Visualforce code.


Flex - Flex is an open source framework for developing rich internet applications. Using Salesforce's APIs you can create very slick applications using Flex. There are a number of built-in UI libraries, as well as a powerful charting library that allows you to create powerful dashboards. Explorer (Submitted by @ashoknaglikar) - Direct from the website: "The Explorer (beta) is a new cross-platform database explorer built with Adobe Flash Builder for It's an AIR app, so you can get started pretty quickly: click here to install."

Governor Limits - Since you are developing in a shared environment Salesforce has implemented a number of limits to make sure your code is not taking up too many resources. If you reach a governor limit, your code will throw an error and stop running.


HTML - HTML stands for "Hypertext Markup Language" Ultimately all of your Visualforce code gets turned into HTML, so if you have an understanding of HTML you will be okay.

Heroku  (Submitted by @knhornt) - Heroku is a could based platform for developing Ruby applications. Salesforce announced that they would be buying Heroku at Dreamforce 2011.


IDE - IDE stands for Integrated Development Environment. The current IDE of choice for development is Eclipse. However, there a number of cloud based IDEs (BrainEngine) popping up that might give it a run for its money.


 jQuery - jQuery is an extremely fast and powerful JavaScript library that is commonly used by developers. It can be downloaded for free and uploaded to your org as a Static Resource.

JSON (Submitted by @osamanasir) - JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language,


Keywords - A set of reserved words that you cannot use when naming variables, methods, or classes.


Log  (Debug Log) – “A debug log records database operations, system processes, and errors that occur when executing a transaction or while running unit tests. The system generates a debug log for a user every time that a user executes a transaction that is included in the filter criteria”.


MVC -  MVC stands for Model-view-controller. It is a software design pattern that is used in development. The idea is to separate the Model (Database or Custom Objects in SFDC) from the View (User interface or Visualforce in SFDC) from the Controller (Business Logic or APEX code in SFDC). 


nullPointerException - If you have ever done any APEX coding, you have probably run into this error. It is defined as "Any issue with dereferencing null".  It can be a frustrating little error that is sometimes hard to debug. You can find some examples of it in the APEX manual below.


Org - This term refers to a particular instance of Salesforce. 


Production - This refers to your "production" instance of Salesforce. All APEX coding must be done in a Sandbox or Developer instance and pushed to production once code coverage is reached.

Query (SOQL and SOSL) - I know this is cheating a little bit since Salesforce's query languages actually start with S and not Q but I had a hard time finding a Q. Anyways, Salesforce Object Query Language (SOQL) and Salesforce Object Search Language (SOSL) are two ways that you can query Salesforce for data. SOQL has a syntax that is very similar to SQL and is primarily used to query Salesforce objects for a list of records that match a specific criteria. SOSL is used to search a list of lists of objects that contain a given search term.


Rerender attribute - Used in Visualforce to do partial page refreshes and create cool user interfaces. Used in this code sample:


standardController - This is the pre-built Visualforce controller that you reference if you create an Extension for a Visualforce page.  

Sandbox - (Submitted by @_siddhesh) - A sandbox is a replication of your production environment in which you do development before pushing to production. Below is a link that outlines the different types of environments.

Sites - (Submitted by @_siddhesh) sites allows you to create public facing web sites and applications that run on the platform and can leverage data in your Salesforce org.


Trigger - Triggers are used to invoke APEX based on data changing in your Salesforce org. Triggers can be run on most objects when records are inserted, updated, deleted, merged, upserted and undeleted.


Unit Tests - "A unit test is code that exercises a specific portion of your codebase in a particular context." In order to get your code from a development or sandbox environment to a production environment you need to have 75% code coverage. This code coverage is gained by writing unit tests for your code. Basically, it is verifying that your code runs the way you think it should with no errors.


Visualforce - Allows you to create any user interface to run on the platform. 


Webservice methods - You can expose your own APEX class methods as a custom web service using the "webservice" keyword. This allows external applications to make calls to your APEX code within Salesforce.


YouTube Salesforce Channel  (Submitted by @pbattison) - A collection of videos that are all about This site is maintained by @CRMFYI

ZIP archives - This is one of my favorite features of development. You can upload a zip file as a Static Resource with a bunch of images, JavaScript code, or whatever and then reference it on your Visualforce pages.