Flex and Salesforce connection: NOT ABLE TO login

2019-08-20 18:37发布

I am trying to log in from flex to salesforce, but I get security error accessing url.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:salesforce="http://www.salesforce.com/"
    layout="absolute" width="500" height="300"
    backgroundGradientAlphas="[1.0, 1.0]"
    backgroundGradientColors="[#FFFFFF, #FFFFFF]" applicationComplete="init()">

    <mx:Script>
       <![CDATA[
        import mx.controls.Alert;
        import mx.collections.ArrayCollection;
        import com.salesforce.results.QueryResult;
        import com.salesforce.results.LoginResult;
        import com.salesforce.AsyncResponder;
        import com.salesforce.objects.LoginRequest;
        import com.salesforce.AsyncResponder;
        import com.salesforce.events.ApexFaultEvent;
        import com.salesforce.objects.LoginRequest;
        import com.salesforce.objects.SObject;
        import com.salesforce.results.Fault;
        import com.salesforce.results.LoginResult;
        import com.salesforce.results.QueryResult;
        import com.salesforce.results.UpsertResult;

        [Bindable]
        private var opps:ArrayCollection;

        private function init():void
        {
            var lr:LoginRequest = new LoginRequest();
            force.protocol = "https";
            force.serverUrl = "https://ap1.salesforce.com/services/Soap/c/15.0";
            lr.username = "my login username";
            lr.password = "pwdandsectoken"; // You may need the security token if so please append the security token eg: passwordsecurityToken
            lr.callback = new AsyncResponder(loginHandler,faultHandler);
            force.login(lr);
        }             

        private function loginHandler(result:LoginResult):void
        {
            Alert.show('login');
            force.query("SELECT Name FROM Account",
            new AsyncResponder(queryHandler, faultHandler));
        }
        private function queryHandler(result:QueryResult):void
        {
            opps = result.records;
        }

        private function faultHandler(result:com.salesforce.results.Fault):void
        {
            Alert.show("Login failed.\nError Code: " + result.faultcode + ':' + result.faultstring + ':' +result.detail);               
        }
        ]]>
    </mx:Script>

    <salesforce:Connection id="force"/>
    <mx:BarChart id="chart" dataProvider="{opps}" top="10" bottom="10" left="10" right="10">
        <mx:verticalAxis>
            <mx:CategoryAxis dataProvider="{opps}" categoryField="Name"/>
        </mx:verticalAxis>
        <mx:series>
        </mx:series>
    </mx:BarChart>
</mx:Application>

This is the code i am using to build swf file. I am not able to log in. I need to embed this form on my Salesforce site.

1条回答
甜甜的少女心
2楼-- · 2019-08-20 19:09

Whats Your Salesforce server instance? You can check it by logging to Salesforce via web browser and it will be presented in the URL just before salesforce.com. Example:

cs7.salesforce.com

Then it might be used in Your server URL. Is it ap1 in Your case?

查看更多
登录 后发表回答