Run SWF file in Salesforce Environment

August 13th, 2009 by nishant.shah § 1

For all the developers who are just starting development in Salesforce may find this article useful. I am going to tell you how you can run an SWF file in Salesforce.

First of all add a reference to the Salesforce namespace to  mx:Application tag and create a connection to the Salesforce.com server.

Eg.

<mx:Application xmls:mx=”http://www.adobe.com/2006/mxml”    xmls:salesforce=”com.salesforce.*” layout = “absolute”/>

<salesforce:Connection id=”apex”/>

The Connection object is already created, so to activate it,Prepare a LoginRequest object by populating the username and password fields. We have to define Callback function(loginResult) that will be fired off when the login response from the Salesforce.com server is received.

Eg.

private function login():void

{

var lr:LoginRequest = new LoginRequest;

lr.username = username.txt;

lr.password = password.txt;

//  lr.server_url = Application.application.parameters.server_url;

// lr.session_id = Application.application.parameters.session_id;

lr.callback = new AsyncResponder(loginResult);

apex.login(lr);

}

No need to give lr.session_id and lr.server_url when running application on local machine.

Deployment

We have three choices to deploy our application.

  1. Deploy it to own server.

  2. Deploy it on Salesforce Environment as an S-Control.

  3. Compile application as an Adobe AIR application and use the new runtime to use the application on the desktop without an application or Web-Server.

Deploy application on Salesforce Environment as an S-Control

To embed the Flex application as an S-Control , compile application for use in Salesforce by modifying the LoginRequest object in code to use the lr.server_url and lr.session_id arguments instead of lr.username and lr.password.

Now log in to Developer account of Salesforce.com and perform following steps.

  1. Click on Setup.

  2. Expand the Develop menu and create S-Control.

  3. Create a new one and give it memorable label and name.

  4. The type will be HTML

  5. In the filename field, browse and select the swf file.

  6. In the content area wirte the following code.

<embed src=”{!Scontrol.JavaArchive}” play=”true”   bgcolor=”#f3f3ec”  width=”100%” height=”100%” name=”FlexSalesforce”  Align=”middle”  flashvars=”session_id={!API.Session_ID}& server_url=    {!API.Partner_Server_URL_90}” loop=”false”allowScriptAccess=”always” type=”application/x-shockwave-flash”  pluginspage=”http://www.adobe.com/go/getflashplayer”</embed>

Here there are three Salesforce.com variables.

  1. Scontrol JavaArchive.

  2. API.Session_ID.

  3. API.Partner_Server_URL_90.

The last two are passed into the SWF when it loads in the browser. These maintain session state. So no need to login while running SWF file.

Now create Tab to house S-Control just created. Create a New Web-Tab with type of Custom S-Control. In step three , Select the S-Control just created to be the content on that tab. Click next through steps four and five. A new tab appear on the top of the screen.

Click on the tab. SWF file will run without required login details.

I hope you found this article useful. Let me know if there are any better ways to do the same thing.

Implementing Salesforce Login Solutuion With Flex 3

July 3rd, 2009 by chirag.babaria § 0

In this post, we will see how we can implement salesforce login with flex.

All you need is:

For the beginner steps for integration of flex toolkit for salesforce you can follow the steps given in below site

http://wiki.developerforce.com/index.php/Tutorial:_Creating_Flex_Salesforce_Mashups

While regarding the login method I will be describing as follows:

The namespaces to be included in flex builder for login are as follows:

connectivity

namespace for flex to salesforce

The Login function will be as follows:

Login

Login method for flex to salesforce

There is a common error while implementing login with salesforce, it will generate following error:

(com.salesforce.events::ApexFaultEvent)#0

bubbles = false

cancelable = true

context = (null)

currentTarget = (null)

eventPhase = 2

fault = (mx.rpc::Fault)#1

errorID = 0

faultCode = “Server.Error.Request”

faultDetail = “Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.salesforce.com/services/Soap/u/11.0"]. URL: http://www.salesforce.com/services/Soap/u/11.0″

faultString = “HTTP request error”

message = “faultCode:Server.Error.Request faultString:’HTTP request error’ faultDetail:’Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.salesforce.com/services/Soap/u/11.0"]. URL: http://www.salesforce.com/services/Soap/u/11.0′”

name = “Error”

rootCause = (flash.events::IOErrorEvent)#2

bubbles = false

cancelable = false

currentTarget = (flash.net::URLLoader)#3

bytesLoaded = 0

bytesTotal = 0

data = (null)

dataFormat = “text”

eventPhase = 2

target = (flash.net::URLLoader)#3

text = “Error #2032: Stream Error. URL: http://www.salesforce.com/services/Soap/u/11.0″

type = “ioError”

message = (mx.messaging.messages::ErrorMessage)#4

body = (Object)#5

clientId = “DirectHTTPChannel0″

correlationId = “026E48D3-1BFD-8AA6-A5D6-CDE8A1C8B7D8″

destination = “”

extendedData = (null)

faultCode = “Server.Error.Request”

faultDetail = “Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.salesforce.com/services/Soap/u/11.0"]. URL: http://www.salesforce.com/services/Soap/u/11.0″

faultString = “HTTP request error”

headers = (Object)#6

messageId = “154CD995-435D-2011-47FB-CDE8A2A25895″

rootCause = (flash.events::IOErrorEvent)#2

timestamp = 0

timeToLive = 0

messageId = “154CD995-435D-2011-47FB-CDE8A2A25895″

target = (null)

token = (mx.rpc::AsyncToken)#7

message = (mx.messaging.messages::HTTPRequestMessage)#8

body = “<se:Envelope xmlns:se=”http://schemas.xmlsoap.org/soap/envelope/”><se:Header xmlns:sfns=”urnartner.soap.sforce.com”/><se:Body><login xmlns=”urnartner.soap.sforce.com” xmlns:ns1=”sobject.partner.soap.sforce.com”><username>[email protected]</username>

<password>xxxxxxxxxxxxx9KYz1Hmt965XXXXQcNVpjaq61</password></login></se:Body></se:Envelope>”

clientId = (null)

contentType = “text/xml; charset=UTF-8″

destination = “DefaultHTTP”

headers = (Object)#9

DSEndpoint = “direct_http_channel”

httpHeaders = (Object)#10

Accept = “text/xml”

SOAPAction = “”"”

X-Salesforce-No-500-SC = “true”

messageId = “026E48D3-1BFD-8AA6-A5D6-CDE8A1C8B7D8″

method = “POST”

recordHeaders = false

timestamp = 0

timeToLive = 0

url = “http://www.salesforce.com/services/Soap/u/11.0″

responders = (Array)#11

[0] (::SalesForceResponder)#12

result = (null)

type = “fault”

Solution

The Flex security model will require that you are running this on https server, unless you specify “http” using connection.protocol();
If your server is not HTTPS, but is HTTP, you can set that on the connection.

In addition, you will need to pass a security token appended to your password unless you have enabled the IP range in your network configuration.

Both will generate the io error you see.

If you are using “HTTPS” then you have to specify

connectionprotocol = “https”

And make sure that in salesforce.com by default “Require secure connections (https)” is checked

HTTPS

Sales force security setting

But if you are using “http”, then you have to specify

connectionprotocol = “http”;

And make sure that in salesforce.com by default “Require secure connections (https)” is checked to false.

HTTP

salesforce https setting

Overview of Flex

May 29th, 2009 by nishant.shah § 1

What is Adobe Flex ?

Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flash Builder or by using the freely available Flex compiler from Adobe.

Adobe Flex takes you to the next level of web application development with the concept of Rich Internet Application(RIAs).You may have seen applications developed natively in Flash itself and realized that it offers a much more robust experience for the user where productivity is bolstered by ease of use,streamlined workflow,and real time interactivity that is impossible to accomplish in HTML itself. However developing rich applications in Flash for those who are core developers is daunting and unintuitive. The Flash development tool is geard for designers, and developing on a timeline is a strange concept. Flex removes that barrier entry by providing a programmatic way for developing these RIAs.

Flex is very prominent and familiar with professional developers. Flex is a set of products designed in an effective way based on efficient delivery of high performance.

Flex is a standard-based programming model for high performance rich internet applications. Flex application will take advantage of adobe flash player 9 and this will enable developer to extend the capabilities enables the client with richer applications in real time.

Flex is a cross-platform development framework for creating Rich Internet Applications(RIAs). A component based tool that you can use to develop apps that run using Flash player or Adobe Air. Adobe Flex Builder software is an Eclipse based IDE for developing RIAs.

Basics of Flex :

  • Runs in the Flash Player or AIR.
  • Tag based markup MXML serves as the basis for Flex Projects.
  • MXML is a custom XML namespace,looks like <mx:MyTag></mx:MyTag>.
  • Component based development : Containers / Layouts Components , UI Elements , Data Connectors.
  • ActionScript 3 can be used to add behaviors or other interactivity not covered by MXML.
  • Supports common OOP practices like MVC patterns,code behind,etc.
  • MXML components can be brought onto the canvas via the GUI similar to Dreamweaver or VisualStudio.
  • Markup can be written by hand with code assist, too. Again, similar to Dreamweaver or VisualStudio.
  • MXML components have attributes that allow for modification of appearance or behavior.
  • Components can be extended for additional capabilities or reuse via MXML or AS or a combo of both.
  • Containers control layout (Canvas, Vertical Box, Horizontal Box)
  • UI components display data, control interactivity or display states or other visual feedback (Datagrids, lists, buttons, selects menus,radio buttons, etc.).
  • Data components load or send data (Services, XML, Remoting, etc).
  • Other tags include: Script, Style, etc.
  • Tags can be nested similar to HTML/XML.

Release history :

  • Flex 1.0 – March 2004
  • Flex 1.5 – October 2004
  • Flex 2.0(Alpha) – October 2005
  • Flex 2.0 Beta 1 – February 2006
  • Flex 2.0 Beta 2 – March 2006
  • Flex 2.0 Beta 3 – May 2006
  • Flex 2.0 Final – June 28,2006
  • Flex 2.0.1 – January 5,2007
  • Flex 3.0 Beta 1 – June 11,2007
  • Flex 3.0 Beta 2 – October 1,2007
  • Flex 3.0 Beta 3 – December 12,2007
  • Flex 3.0 – February 25,2008
  • Flex 3.1 – August 15,2008
  • Flex 3.2 – November 17,2008
  • Flex 3.3 – March 4,2009

What is Flex Builder ?

Macromedia recently released Flex Builder (formerly known as “Brady”), an IDE based on Macromedia Dreamweaver MX 2004. Bundled with the Flex application server, Flex Builder provides a WYSIWYG environment for creating Flex applications, an integrated debugger, and code hinting for ActionScript and MXML (plus all of the features supported by Dreamweaver).

The IDE still shows some rough edges. For example, clicking “Help” in the “Manage Sites” dialog launches “Using Dreamweaver,” not “Using Flex Builder.” So, if you get stuck in the middle of defining a new Flex site, you won’t have access to Flex Builder’s excellent support documents. In test instances, opening any “On Demand” video tutorials launched Mozilla-even though it wasn’t set as the default browser.

Perhaps the best way to get a sense of the productivity benefits of Flex Builder is to compare it to Macromedia’s other Flash IDE, Macromedia Flash MX 2004 Professional. Both IDEs support a component called “Accordion” that provides a compact interface widget for showing and hiding information. A Flash developer can drag the Accordion component to the stage, but to populate it with data must use the ActionScript Accordion.createChild() method to instantiate a UIObject or link an existing symbol. It’s not rocket science, but it is time consuming. A developer working with Flex Builder, on the other hand, can simply drag an Accordion container to the stage and populate it with drag-and-drop controls such as form widgets or images. The difference in productivity is an order of magnitude. Think of Flex Builder as Visual Studio.NET Light for Flash.

Advantages of Flex :

  • Flex applications can be intuitive, easy to use, and almost have the feel of the desktop.

  • Easy to program and deploy.

  • Can be deployed right now on 50% or more of the world’s browsers, with ubiquity increasing daily.

  • Dedicated IDE based on Dreamweaver available now.

  • Doesn’t require a large client installation like the .NET runtime.

  • Extensive Visual component library.

  • Powerful coding tools.

  • Scalable and reliable solution.

  • Superb Flex programming model.

  • Easy Integration into a server application.

  • High performance data synchronization engine.

  • Interactivity due to video, audio, streaming and messaging components.

Disadvantages of Flex :

  • Macromedia has poor track record with servers and server tools.

  • Expensive.

  • No free developer download.

Examples :

  • To get record from DataGrid from particular row and column :

    • var SelectedData:String = DataGrid.dataProvider[event.rowIndex][DataGrid.columns[event.columnIndex].dataField];
  • To create Custome Menu on right click :

    • private var cm:ContextMenu = new ContextMenu();

      cm.hideBuiltInItems();

      var newMenu:ContextMenuItem =

        new ContextMenuItem(“View Item”,true);

      newMenu.addEventListener(ContextMenuEvent.Menu_ITEM_SELECT,

      doMenuFunction);

      cm.customItems.push(newMenu);

    • private function doMenuFunction():void

      {

        Alert.show(event.currentTarget.caption.toString());

      }

      It Shows Selected Menu Item.

Where Am I?

You are currently browsing the Flex category at Digicorp.