Posts Tagged ‘Flex’

Time Zone issue with Salesforce toolkit for Flex

November 1, 2010

Use Case for GMT +5:30

If a date is saved having the time HH hours and minutes between 0 to 29, the force-flex.swc toolkit serializes this date with time zone offset having additional 1 hour difference. So the date saved in the database will have one hour difference than actual date sent. This is because the logic written in Util.as class of the toolkit is not considering the difference between UTC and local time when the difference in minutes is negative. So the resultant time zone has additional 1 hour offset.

Consider the following case:

A date passed to the dateTimeToString function in Utis.as class in the toolkit is 16/02/2010 (mm/dd/yyyy format) and time 16 hours and 15 minutes.(Note the date specified is for GMT +5:30)

Date sent to Salesforce

The date after conversion is as shown in the soap message taken from httpfox tool of Mozilla firefox.

As seen from the soap message, the StartDateTime has the time zone set as +06:30 which is not the expected time zone.

Why this happens?

Consider the time for given date. Its 16 hours and 15 minutes.  When calculating time zone difference, the code in dateTimeToString function in Utis.as neglects the negative difference between the minutes. When the user enters 16 hours and 15 minutes, it will be 10 hours and 45 minutes in GMT(UTC). But during calculation what is happening is the difference between the hours and minutes is directly considered as time zone offset which in this case will be 6 hours (16 – 10) and -30 minutes        (15 – 45). As the –ve sign for minutes difference is neglected, it is reflected as 1 hour additional difference in calculated hour for time zone.

Fix for the Bug

To fix the bug, just put a check in Util.as class in the function dateTimeToString as shown below:

Time Zone issue Fix

I hope someone will find this helpful as I spent 2 whole days figuring out what the problem was.

INVALID_FIELD: No such column ‘type’ error in flex salesforce communication

October 29, 2010

While trying to pass a custom object in salesforce from Flex. If you encounter the below error. Especially if you are passing a wrapper class to the webservice method.

“INVALID_FIELD: No such column ‘type’ on entity . If you are attempting to use a custom field, be sure to append the ‘__c’ after the custom field name. Please reference your WSDL or the describe call for the appropriate names.”

This occurs because the flex salesforce toolkit forces a property type while creating request parameters to be serialized with salesforce.

There are 2 solutions to this: First the not so attractive one is to convert everything to wrapper classes and send all data as SObjects. This will add overhead on salesforce  side to manage the conversion of object.

Second, go to Salesforce flex toolkit and add a condition to the SObject class on line 101:

if(this["type"]){
this.writeValue(sobjectNs, writer, "type", this["type"]);
}

This should solve the issues of not being able to send the data to salesforce.

Flex Framework for SalesForce Apps- Part 4 Application

October 28, 2010

Now that we have seen the concepts, understood how flex and salesforce can talk to each other. Time to see an application build with this approach. You can download the application from here (Right click and select download linked file as..)

And the library Project from here.

For every call what needs to be done is very simple: Create a controller, add mapping and dispatch an event with bubble set to true.

Import the FXP and the FXPL into your flash builder and put the correct configuration in for salesforce  and your code should be working.

The responder handles the result or fault. RC4SF can be used with any existing framework like Mate or SWIZ. Personally I find code based configuration better than writing XML based configuration in my code and hence the approach. We intend to put all those things online as soon as we are able to breathe a bit out of our consulting assignments 😉 We ‘ll keep exploring and posting it here.

As I sign off  this series a small note. This is not a new framework. We have used this for a while not and almost all frameworks use the same principles. We have combined what we knew was the best and here one that suits us the best. Feel Free to Modify the source code or use any part that you think will be useful for your project.

Up next: Using Melrose: Putting AIR apps on the Intel AppStore and more 🙂

Flex Framework for SalesForce Apps- Part 3 Working

September 18, 2010

In the last part we have seen the framework specifics. In this part lets see how it all comes together. There are several classes that we need to create. Before we get there lets look at the way the salesforce toolkit works.

There are a few toolkit classes that we need to know:

Connection: This class is responsible for communication with SFDC. Connection allows querying as well as calling webservice methods. For metadata the Connection2 class has to be used. The key methods are login() and execute()

AsyncResoponder: When a request is sent to salesforce a responder is associated to it that is responsible for handling the result/fault for that call.

Parameter: All request parameters need to be sent as an Array of objects of type  Parameter class. A vector would have been ideal in this case however the toolkit comes from Flex 3 days.

Lets look at the framework components and the end to end flow.

The core idea is MVC based where we have a controller who is responsible for making decisions on service and handling the business logic.

The fundamental approach of accessing the service is the Command pattern. This is pretty much like cairngorm except the fact that we are using the com.salesforce.AsyncResponder class for handling responses. The reason is simple. The execute method in the Connection class expects and object of AsyncResponder. Hence we can simplify the code drastically.

The Command class can be seen as a helper to the main Controller class where it takes away a responsibility from the controller of sending a particular request and handling its response. It implements an ICommand interface which includes an “execute” method. This method is responsible of sending the service call and extends from the AsyncResponder class due to which the result and fault methods need to be overridden.

All these requests are generated from a view (or other commands) where the notification travels in form of an event to the controller and based on the event the controller invokes the correct Command. This does not require the event to be of a specific type rather it can be any event with the bubbles property set to true.

RC4SF - view controller

RC4SF (View Controller Flow)

The Connector class is the service layer which in our class is a class with 2 static members. First the connection object from salesforce which can be used for login or describing an object. And second the invokeSFDC method which will call the correct webservice method.

The steps are simple:

1. Create and instance of the Controller and pass the reference of the main application

2. Dispatch an event from application with bubbles set to true

3. Create a command to handle request from the events

4. In the controller add association of the event being dispatched with the Command

5. Call the SFConnector classes invokeSFDC with correct parameters

6. Handle result/fault in the responder which called the request

Here is the code for this bit. At the end of all parts will be uploading the framework and a sample/template application

/**
Connector class
*/
package com.tekno.rc.service

{

import com.salesforce.AsyncResponder;

import com.salesforce.Connection;

public class SFConnector

{

public function SFConnector(){

}

public static var connector:Connection = new Connection	();

private static var _webServiceClass:String;

private static var _namespace:String;

public static function set webServiceClass(value:String):void{
_webServiceClass = value;
}

public static function get webServiceClass():String{
return _webServiceClass
}

public static function set namespace(value:String):void{
_namespace = value;
}

public static function get namespace():String{
return _namespace;
}

public static function invokeSFDC(method:String,args:Array,responder:AsyncResponder,webServiceClass:String="",namespace:String=""):void{

var _ws:String = _webServiceClass;

if(webServiceClass.length > 0){
_ws = webServiceClass;
}

var _ns:String = _namespace;

if(namespace.length > 0){
_ns = namespace;
}
connector.execute(_ws,method,args,responder,_ns);
}
}
}

The Control class:

package com.tekno.rc.control

{

import com.tekno.rc.control.commands.ICommand;

import flash.display.DisplayObject;

import mx.rpc.AsyncResponder;

public class Controller
{

private var app:DisplayObject;

public function Controller(app:DisplayObject){
this.app = app;
}

public function mapCommandToEvent(eventName:String,responder:ICommand):void{
app.addEventListener(eventName,responder.execute);
}

}
}

In the next part we see an application working with the framework. And the entire source code

Flex Framework for SalesForce Apps- Part 2 The Framework

September 9, 2010

In the last part we ‘ve looked at  basic terminology its time to take a deep dive into the architecture now. Just before we go on there is one small disclaimer here:  This is not a tutorial on how to integrate flex with salesforce, you can find a bunch of them every where, this one is to understand ways in which you can architect an application to leverage the existing arrangement.

Now that we are even, lets look at the framework, it is based on existing Rapid Connect (thank you, Abdul Qabiz for the name) framework that we use extensively and  uses 2 principles from Bruce Lee’s JKD.

  1. Use Lesser Resources (Keeping it simple)
  2. Tailor make it to your requirement

Like JKD which is a fighting philosophy which combines various methodologies (best of all worlds) we are going on a similar approach in taking best of existing framework/micro architectures and simplifying it greatly. “If its not simple, its not right.”

The core of the Framework is a simplified version of any MVC framework that you can think of, uses existing classes from the flextoolkit provided by SFDC to manage commands and responders (ala Cairngorm) and reaches them using Flex’s event propagation capability (any DI architecture like mate, swiz…) and coupling this with the requirement to push data from a non UI class to use a GenericEventDispatcher which I described in an earlier post. You may want to use this or may not want to user this.

It uses simple MVC approach:

MVC in Flex

MVC in flex regardless of the micro architecture you use leverages 2 major Flex principles.

1. Event Mechanism (invoke controller)

2. Concept of Binding (Model updates views)

However, this is a 10,000 feet view as we go deeper there are specifics and intricacies that are involved. Here  we take a closer look at the architecture we are using and then define each of its entities and see how it all comes together.

Rapid Connect for SalesForce RC4SF (Yes that’s what we are going to call it, at least for now) looks like this:

Rapid Connect 4 SalesForce

Rapid Connect 4 SalesForce

The Entities here are:

1. The View: is any UI component, typically an MXML one which can dispatch an event (with bubbles set to true)

2. The Controller: is an entity that listens to the events coming from the view and handles them

3. The AsyncResponder: is a class which is something like a command class in Cairngorm earlier versions however it uses the salesforce AsyncResonder instead of using an interface and overrides the result and fault method (Here you can decide if you want to call the service from here or you want controller to handle that part. More about this in part 3)

4. The Connector: is the class that plays a role of a service class. This class contains the SFDC connector obejects and calls methods to login, invoke a webservice method and get metadata

5. The GenericEventDispatcher: is a singleton EventDispatcher which is responsible for inter-application communication in a more effective manner (in the past people have been using Application.application for this purpose)

6. The Model: is your data store. This can be a singleton (if you are a fan of Cairngorms ModelLocator approach) or can be VO classes. You can either use binding to update the objects or use the generic event disaptch mechanism if you have to invoke something on the UI.

This broadly covers everything that we need to cover for the framework.

Up next in part 3: The working of the Framework and some code

Flex Framework for SalesForce Apps- Part 1 Warm Up

September 7, 2010

We have been working on a few sales force – flex apps for our customers since last September. Initially all the entities involved can really overwhelm you. It is extremely critical to get the application architecture right because the data model is mostly dynamic and also the toolkit has its own overhead.  We are trying to share the approach that we use to build SFDC – Flex apps.

Let warm up. Starting from salesforce terminology:

1. ToolKit: Salesforce.com provides a toolkit (actionscript library) using which you can communicate with the salesforce.com platform. Using this toolkit gives a head start to your SFDC- Flex Apps

2. Apex Webservices: SFDC has a language called Apex using which you can create webservices to access you application. It is predominantly based on Java, however, there are a few restrictions

3. Visual Force: VisualForce or VF is a UI technology for salesforce, primarily driven on Ajax it allows integration of Flash components (read SWF) into it. You can write JavaScript into it and hence has a big advantage. There are other UI things like S-Controls which we need not look into now.

4. Static Resource: In simple terms a static resource is any media,document,file which needs to be uploaded to SFDC for your project. So the SWF will be uploaded as a static resource. (Rather the entire output folder from flex)

5. <Apex:Flash>: This tag is used inside the VF page to help you embed swf. You can pass FLASHVARS set height, width.

6. Briefcase (AIR apps): Briefcase is a SalesForce concept using which you can create off-line applications. Add objects to the briefcase (though some objects like case can not be added to it) and then you can sync data from your off-line application.

7. Org: Your part of salesforce.com which you can customize and use as your requirement. Every customer has his own org and his own installation (package) of the application

8. sObject: sObject refers to any object that can be stored in the Force.com platform database. An sObject variable represents a row of data and can only be declared in Apex using the Web services APIname (the name with which the object is identified) of the object. This is of high importance as most webservice communication will involve sObjects

You can build you project either based on web-services or write the business directly onto the flex calsses, we do not use the later as we want flex to be unaware of the core business and keep it as generic as possible. However the framework is equally applicable to any type of project. ideally on the salesforce front if you are making webservices there should be good care taken to ensure only one webservice class is exposed to flex and the rest of the things can be in remaining wrappers.This keeps the architecture much more robust and generic.

Some warm up on the flex side (assuming you know flex):

1. Depending on the type of project you want to build (Flex or AIR) include the SWC of the toolkit which can be downloaded from here

2. It is good to have the code linked for the SWC since you will need to go to and fro

3. Setting up the architecture:

Apart from flex UI, the architecture contains 2 key elements: 1. The Controller and the Async Tokens

In the next part we exclusively look at the concept of the architecture, various entities and the working.

Learn Flex from Champions for Free !!

September 6, 2010

Adobe Flex is picking pace and is reaching a more organic level viz. the student community in India, and rightly so. If the next generation of engineers come equipped with knowledge for technologies like Flex, ColdFusion, Silverlight, Scala etc it will give Indian IT a new high.

There are lot of initiatives that are going on currently to spread Flex around. Like Adobe’s Flex@Campus which gives educational organization across India to leverage a free 1 day training on Adobe Flex. The flex community in India has extended its support to it. Because it is a hands on program, it gives you a head start into the technology allowing you to create a base on which you can build up.

Then there is RIA Connect. It is a Tekno Point initiative that is not restricted to Flex alone. It could me on any Adobe Product like Photoshop, Illustrator, Flash Professional, Flex, ColdFusion. It is a 1 day program for corporates, educational institutes or any other organization allowing them to understand the underlying abilities of the Technology and a follow up hands on session to get them started. The contents of this one day workshop are modified keeping the audience in mind. For Designers/ Devs there is more of  hands on and for business heads, architects there is more breadth in which the workshop topics are covered.

Don’t wait to get started. Go to the links and fill the forms to take your first step, as common sense says “To reach anywhere, you have to start from the beginning and go through the middle”

Alternative to Application.application

August 27, 2010

If you are using Application.application in your code you aren’t probably doing the best thing to your code for reasons more than one. Like Flex 4 no longer supports it, While using sub-applications or modules it will end up in trouble and MOST IMPORTANTLY it will tightly couple your application to the component

Instead, for most cases you (if you are dispatching an even using Application.application) you can set the events bubble property to true and listen to the same events at the application level. This will work for itemRenderers in DataGrid’s too.

Other option is to use a GenericEventDispatcher that extends from EventDispatcher and can be a singleton. So instead of dispatching an event using Application.application.dispatchEvent you can instead use GenericEventDispatcher.instance.dispatchEvent. This will work across all components and also between modules and sub-applications.

The business of wire-framing

July 17, 2009
With emergence of web 2.0 everything is going online. Websites are no longer small partly usable entities but have grown in to become full fledged applications. With this the scope and expectation of a web application have risen dramatically over past 2 years. Everybody want’s an intelligent good looking and robust application developed quickly and in budget. But how good does it go when we get real?

If you want a web-application to be developed or are a developing one it is extremely important to look at the process that you are following. Some rough requirement document, some inputs from the technical team and some rough ideas? Why do you think so many software projects fail or lose track and overshoot time and effort estimation?

This incorrect estimation comes due to lack of clarity of the requirement and the process. Isn’t there a clear disconnect between your ideas and the person who is implementing them? How do you bridge the gap? The answers is WIREFRAMES

So, what is a wire-frame:

A wire-frame is a pictorial representation of data (and not design) of your application.  Creating a wire frame is normally an iterative process which involves some Business intelligence, Product technical know how and a usability analyst to come together. It could be a PPT or there are several tools available like Omnigraffle, Axure, MockupScreens or for that matter open office draw. It is like they say, always write an algorithm before you write an implementation. Wireframes bring an application flowchart and work flow algorithms to an easily understandable level.

In the first iteration ideally you would want the person who understands the business to roughly sketch his ideas on a piece of paper. As an iteration a Usability Analyst armed with the technical know how and behavioral aspects of a web application can start mapping them onto a wireframe.

Wire frame is not how your application but what it contains and some part of how it behaves.

 The 3 major advantages which impact everything from time to cost and success of the project are:

1) Wireframes increase the clarity about the application that you are getting developed or developing. If  there are any uncertainties or challenges they can be handled right at the beginning. The picture becomes more clear on every single piece of information that the system will get in or display. You do not want to create something you cannot sell, right?

2) Better estimation of cost and time: No doubt creating a wireframe would bring in its overhead on cost and time. But if you look at the overall picture it simplifies things for a developer/technical architect to such an extent that they can virtually see what they want. Also a  designer can create the views with better understanding and focus.

3) Project management: As the application grows and comes closer to being realized that’s when you can expect some major surprises. A wire-frame coupled with an iterative release process will ensure that you get what you expect

It is again not necessary that you stick to the wire frame as is. While the application gets developed there will be challenges and constraints however the magnitude of problem and the time taken to get over them will reduce drastically

I think in a nutshell. No wireframes there is a very little chance of you getting a quality product in time.

 

A sample wireframe:

A Sample Wireframe build with powerpoint

BlazeDS + IE+ HTTPS issue

July 14, 2009

Problem:  While using blazeDS content is not transferred over HTTPS this may be because of a firewall or a reverse proxy like web-seal in deployment.

So if you have blocked the port 80 on server you will notice that application gets loaded but calls are throwing a ChannelFaultEvent.

Reason:

The request coming in from client over https hits the firewall which should be the endpoint URL and because of this the server side(firewall) should fire the request on the non-secure/HTTP port of BlazeDS server.

Solution:

The configuration of the channel should look something like

<channel-definition id=”secure-amf” class=”mx.messaging.channels.SecureAMFChannel“>
   <endpoint url=” {contextRoot}/messagebroker/amf” class=”flex.messaging.endpoints.AMFEndpoint“/>
   <properties>
                 <add-no-cache-headers>false</add-no-cache-headers>
</ properties>
</ channel-definition>

 Notice the client uses a secure channel and the server uses an insecure endpoint

Cheers,

Y


%d bloggers like this: