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.
-
Deploy it to own server.
-
Deploy it on Salesforce Environment as an S-Control.
-
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.
-
Click on Setup.
-
Expand the Develop menu and create S-Control.
-
Create a new one and give it memorable label and name.
-
The type will be HTML
-
In the filename field, browse and select the swf file.
-
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.
-
Scontrol JavaArchive.
-
API.Session_ID.
-
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.
Hi buddy, your blog’s design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!