Handling asynchronous Flex calls to Salesforce.com using an MVC framework

June 3rd, 2008

I’m working on a Flex applications using the Flex Toolkit for Apex and Model-Glue:Flex as the MVC framework. I’ve got my main applications, controllers, models and views working well. One on my requirements is to make a call to Salesforce.com, fetch some user settings and then display a specific canvas depending on the returned values.

I dispatch an event, the controller makes the request to Salesforce.com and passes it a responder to process the returned results. However due to the asynchronous nature of the Flex Toolkit, I don’t really know when the results are returned from Salesforce.com. Here’s my solutions to notify my application when results are returned by Salesforce.com.

I setup a private member to track the status of the transaction:

1
private var _transactionComplete:Boolean;

I couldn’t use public members as I wanted to listen for changes to _transactionComplete so I had to write getters/setters for the data binding and to process the notifications when the value was set:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[Bindable]
public function set transactionComplete (value:Boolean):void
{
    _transactionComplete = value;
}
 
public function get transactionComplete ():Boolean
{   
    if (_transactionComplete == true) {
        showCanvas();
    }
    return _transactionComplete;        
}
 
public function showCanvas():void {
    if (accountController.user.isAdmin) {
        // do something
    } else {
        // do something else
    }
}

Since my controller does all of the heavy lifting, I added the following line to the responder which notify my application that the results have returned from Salesforce.com (Of course I have to reset my transactionComplete to false before I make the initial call to Salesforce.com):

1
Application.application.transactionComplete = true;

I’m not sure if this is the best method, but it solved my issue.

  • Share/Bookmark

Related posts:

  1. Cool Code at Lunch Webinar – Flex & Salesforce
  2. Developing Salesforce.com Applications with Flex and Visualforce
  3. Displaying Validation Messages with Flex and Salesforce.com
  4. Developing Flex Applications for Force.com Sites
  5. Flex Callback Example with Visualforce

Categories: Flex, Salesforce

Leave a comment

Leave a comment

Feed

http://blog.jeffdouglas.com / Handling asynchronous Flex calls to Salesforce.com using an MVC framework