function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
agni.fireagni.fire 

Flex: Salesforce.com Connection object: seperating UI from Logic

Hello,

Before I begin, thanks to everyone on this forum for being so helpful.

Our team is currently in the process of building several flex screens that integrate with salesforce.com. I have run into problems seperating the UI from the "business/db" logic portion

We have been able to get a few of our screens integrated into salesforce.com, but I don't like the fact that I have to place all the soql query logic , all the business logic on the front end piece of the code.

I wanted to build a class( databaseClass) that takes care of logging into salesforce.com and running all the queries and passing those values back to the mxml front end, but I have run into a lot of problems. I am attaching a sample of the code. I was wondering if someone could tell me or point to what I am doing wrong.

I know that on every mxml page, I have to include
<salesforce:Connection id="apex"/> and this works great, so I have created a Connection object in my class.

The  control doesn't break, but the apex object is always null.  Any help is appreciated.

Step 1: DB Class: DBAccess.as
     import mx.utils.ObjectProxy;
      import mx.collections.ArrayCollection;
      import mx.logging.Log;
      import mx.utils.ObjectUtil;
      import mx.controls.Alert;    
    import com.salesforce.results.*;
    import com.salesforce.events.*;
      import com.salesforce.objects.*;
      import com.salesforce.*;

    public class DBAccess
    {
        private var _data: Object;
        private var queryResult:QueryResult;
        private var apex:com.salesforce.Connection;      // salesforce.com Connection object    
       
        public function DBAccess()
        {
        }
        public function login(server_url:String,session_id:String):String
        {
            var boolLogin:int=0;
            var lr:LoginRequest = new LoginRequest(    {    
            server_url : server_url,   
            session_id : session_id,
            username : 'username@domain.com',             // put your own info here to test standalone
            password : 'pwd',            // put your own info here to test standalone   
            callback : new AsyncResponder(function (result: Object):void
                {
                    boolLogin=1;
                } )
            } );
           
        //Util.debug(this, 'apex.login ( ' +ObjectUtil.toString(lr) +'\n);' );   
            apex=new Connection();
            apex.login(lr);
            return boolLogin;
        }      
    }
Step 2: calling the class file
              var lr: DBAccess = new DBAccess();
              var vlogin:String=lr.login(this.parameters.server_url,this.parameters.session_id);
              ta.text=vlogin.toString();

Thanks in advance.

Message Edited by agni.fire on 08-20-2007 01:06 AM

agni.fireagni.fire
Hello,

I was able to figure this out. It was pretty easy. I need to pass parameters.server_url and parameters_session_id into login and I was able to get a connect .

fullvaluefullvalue
Hello,
  I was using your call and I get the following error: 

1119: Access of possibly undefined property parameters through a reference with static type Class.


On this line:
var vlogin:String=lr.login(this.parameters.server_url,this.parameters.session_id);

Error Def:

1119Access of possibly undefined property _ through a reference with static type _. You are attempting to access a property that does not exist for the specified object. For example, the following code generates this error because an int object does not have a property named assortment:
var i:int = 44;
var str:String = i.assortment;
This error appears only when the compiler is running in strict mode.


It does run and everything is ok but is there a way to structure this or we don't get this error? 

Also, is there a way to structure all of this so we only have one instance of this class and we can get it from anywhere in the application?  OR am I way off.  I'm new to all of this....Thanks.