Developing Flex Applications for Sites

Developing Flex applications for a Site is a little different than developing Flex applications that run inside the standard UI. Since visitors are not required to log in to your Site there is no concept of an actual user. All visitors simply run as a specific profile under the Guest license.

Since there is no named user for Sites, there is no associated session to pass to your Flex application. Therefore, you need to explicitly code a username and password to log into in your Flex application. This is a similar concept to authenticating via web services to

Here's a quick example of a Flex application running on my developer Site. You can run this demo on my Developer Site.

Here is the Visualforce page running in my developer Site.

  <apex:sectionHeader title="Required Field and Validation Example"/>
  <apex:pageBlock >

 <apex:flash src="{!$Resource.DisplayValidation}"
  width="500" height="300"/>


The Flex application specifying the username and password with which the application authenticates.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=""
  backgroundGradientAlphas="[1.0, 1.0]"
  backgroundGradientColors="[#F3F3EC, #F3F3EC]"
  height="300" width="500">

  import com.salesforce.*;
  import com.salesforce.objects.*;
  import com.salesforce.results.*;
  import mx.controls.Alert;

  [Bindable] public var sfdc:Connection = new Connection();

  private function login():void {

  var lr:LoginRequest = new LoginRequest();
  sfdc.protocol = "http";
  sfdc.serverUrl = "";
  lr.username = "YOUR_USERNAME";
  lr.password = "YOUR_PASSWORD_AND_TOKEN";
  lr.callback = new AsyncResponder(loginSuccess, loginFault);


  private function submitForm():void {

   var aSo:Array = new Array();
   var so:SObject = new SObject("Contact");
   so.FirstName = firstName.text;
   so.LastName = lastName.text;
   so.Email = email.text;


    new AsyncResponder(
     function (obj:Object):void {
      if (obj[0].success == true) {"Created record: "+obj[0].id);
      } else {[0].errors[0].message)
     }, sfdcFailure


  private function loginSuccess(result:Object):void {
   contactForm.enabled = true;

  private function sfdcFailure(fault:Object):void {;

  private function loginFault(fault:Object):void
  {"Could not log into SFDC: "+fault.fault.faultString,"Login Error");

 <mx:Text text="To create a new Contact, Last Name is required by while Email is required via a custom validation rule. &#xd;&#xd;Submit the form with different combinations to view the resulting messages returned from;" width="449"/>
 <mx:Form id="contactForm" width="100%" height="100%" enabled="false">
  <mx:FormItem label="First Name">
   <mx:TextInput id="firstName"/>
  <mx:FormItem label="Last Name">
   <mx:TextInput id="lastName"/>
  <mx:FormItem label="Email">
   <mx:TextInput id="email"/>
   <mx:Button label="Submit" click="submitForm()"/>