Salesforce Flex / Apollo Sample – Offline Data Sync

On Monday I presented at the Salesforce Developer Conference in Santa Clara. It was a great conference! The keynote was especially exciting because it kinda turned into the Flex/Apollo show. Near the middle of his keynote Marc Benioff went on about how great Adobe is for innovating with Flex and Apollo. He then brought Kevin Lynch on stage who did his usual Apollo demos, which filled the crowd with “Ooos” and “Ahhhs”. Then they brought up someone who built some amazing Salesforce based applications. And guess what? It was a Flex app running inside a Salesforce S-Control! Then Adam Gross and Parker Harris from Salesforce took the stage to present even more Flex applications! It felt for a second like I was at Max!

I was pretty excited to see all the broad uses of the Flex Toolkit for Apex which has been the catalyst for Salesforce jumping further into the Flex & Apollo world. The Toolkit started as one of my “plane projects” where I took the existing Salesforce JavaScript library and did regex replaces on the code, moved the prototype stuff to proper classes, added static typing, and finally got the thing to compile. Thanks primarily to Dave Carroll and Ron Hess from Salesforce as well as Seth Hodgson from the Flex Data Services team, the Toolkit evolved well beyond a “plane project” and is now being used in demos and production applications!

Back to the conference… Throughout the day I stopped by the Adobe demo pod to show demos and give out Apollo books. Dave Carroll and I also co-presented a one hour session to a packed audience of about 250.

The use of Flex and Apollo in the Salesforce world is taking off! Like I said in my session on Monday… Salesforce is revolutionizing how we build back-ends! Flex & Apollo are revolutionizing how we build front-ends! Bringing these two technologies together is a perfect match!

Now on to the Salesforce Apollo Sample…

AccountTracker2.air – Apollo Sample (Requires Apollo Alpha)

This Apollo application is one of the samples we are working on for the Flex Toolkit for Apex. It has some cool offline data sync capabilities. However currently the sync is only one way and some of the application is just smoke and mirrors (the chart data is fake because I was in crunch mode getting this ready for the Web 2.0 conference). But it really does pull most of its data from and syncs data and files to the local system so that it works offline. I can’t take credit for much of this application. I did some polishing but most of the work was done by Dave Carroll and Ron Hess from Salesforce. They have both put in a ton of work to the Toolkit and the samples. So big thanks to them!

If you want to see how to start building Flex and Apollo applications using the Flex Toolkit for Apex, check out these resources:

Flex and Apollo in Vegas

This week I’m in Vegas for a few presentations. First one is at the Interop conference on Wednesday. Interop is a fun place for me because I get to hang out with networking / sys admin folks. In a past life I was a sys admin (thus the reason why I love vi). :)

On Thursday night I am presenting at the Vegas Adobe User Group and really looking forward to meeting some of the Flex friends I’ve only known via email, blogs, twitter, etc.

I was also supposed to present at the local JUG but the meeting was canceled because there was a conflicting conference that everyone was going to be at. Oh-well. Time to go lose money instead!

The Open Source Flex and Apollo Toolkit for

A few months ago I met with about Flex and Apollo. They had begun building some Flex applications that used the Flex Ajax Bridge to communicate with Salesforce. This worked but they wanted to be able to more easily build Flex and Apollo applications. So I took their JavaScript library and did an initial port to ActionScript. Surprisingly the code ported pretty easily. It was actually a fascinating experiment. ActionScript 3 is based on the same specification as JavaScript 2, so in theory this kind of thing should be pretty trivial — especially if the code being ported doesn’t do much with the browser DOM. That was the situation in this case because the Salesforce JavaScript library talks to their backend via XHR and doesn’t do much with the browser DOM. Once I had an initial port done including authentication and query support Ron and Dave from cleaned everything up, added better object typing, built complex examples, and developed an Apollo demo. Everything has been going on under a semi-secret SourceForge project, code named Mavericks.

“Adobe Flex Toolkit for Apex” is the formal name for this new Flex / Apollo library. The library is licensed under BSD so everyone can easily reuse it in their applications. Because it uses a simple asynchronous communications model and typed objects wherever possible, this new library accelerates the process of building Flex and Apollo applications on top of the Apex platform. With just a few lines of code you can get data from and render it in your application. There are three primary ways to use this toolkit. You can use it to build Apollo based desktop applications, create custom web applications hosted on your site, or build a custom S-Control hosted on For instructions on how to build a custom S-Control and the basics of using the toolkit, check out the Creating Flex Salesforce Mashups tutorial.

Here is what you need to do to build an Apollo application using the Flex Toolkit for Apex.

1. Download the toolkit:

2. If you haven’t already done so, install Flex Builder and the Apollo Extensions:

3. Create a new Apollo Project

4. Add the Salesforce SWC to the Library Build Path

5. Write your Apollo application:

<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="" xmlns:salesforce=""
  creationComplete="conn.loginWithCredentials('dev@mavericks.demo', '123456', new AsyncResponder(loginResult, loginFault));">

  import mx.controls.Alert;
  import com.salesforce.results.QueryResult;
  import com.salesforce.AsyncResponder;
  private function loginResult(result:Object):void
    conn.query("SELECT Id, Contact.Firstname, Contact.Lastname FROM Contact",
      new AsyncResponder(queryResult));
  private function loginFault(fault:Object):void
  {"Login error!");
  private function queryResult(qr:QueryResult):void
    dg.dataProvider = qr.records;

  <salesforce:Connection id="conn"/>
  <mx:DataGrid id="dg" width="100%" height="100%"/>

6. Save it (which automatically compiles it)

7. Run it

8. Export it as an installable AIR file so you can share it with others

9. Say “WOW!”

It really is that easy. To learn more check out the examples in the toolkit. Also if you really want to dive in, the toolkit is 100% Open Source so you can look at all the code and even help us improve it. Check it out from the SourceForge SVN repository. I’m working on another article which will walk you through setting up the environment to begin hacking on the toolkit using either the Free Flex SDK or Flex Builder (we support both methods). I hope you find the toolkit useful and please let me know what cool things you build with it!

My Recent Flex & Apollo Adventures

Sorry this blog has been pretty stagnant lately. Things have been totally crazy. I’ve been touring the country speaking at Java User Groups and other conferences. The JUGs have been really fun. It’s amazing to see how quickly the Java crowd falls in love with Flex, like I did a few years ago. There are still more JUGs, conferences, and eSeminars coming up so please check out the schedule and see if I happen to be in your home town sometime soon. If you will be around the Bay Area for JavaOne, we will be throwing a huge bash with Bruce Eckel. The details are still being finalized, but stay tuned. Also coming in October is the annual Adobe developer conference, called MAX. It will be full of top notch Flex sessions by many of our star engineers. Definitely not something you want to miss. In May I’ll be doing a triple header in Vegas; Las Vegas Adobe User Group, Nevada Java User Group, and Interop. Hopefully some of these events are in your home town since I’d love to meet you all in person!

Four other quick things…

Today we announced the Adobe Flex Toolkit for Apex which allows you to very easily create Flex & Apollo apps on top of SalesForce. I have been working on this project for a few months so it’s exciting to see it launch. I’ll be posting another blog in the next few days with more details about using the new Toolkit in Apollo applications. But if you want to get started, check out the Creating Flex Salesforce Mashups tutorial.

A while back Bruce Eckel and I recorded a screencast of us building a Flex application with Hibernate and XFire on the backend. I finally got around to packaging the code for that demo. You can get it from SourceForge.

My friend Tony in Japan created a pretty cool Flex app that does text diffs. Very cool and nice use of vectors! Thanks Tony!

Lastly, there has been lots of great developments going on with the Meldware Communications Suite. They use Flex for the webmail client. It is coming along very well, but we need some help. If you know Flex and want to get involved in a great Open Source Flex project, get more info on the site. Also, Meldware is doing a Linux User Group tour. Check out their schedule.