Flex on salesforce站点错误

时间:2014-06-29 05:38:08

标签: flex login salesforce sites

我在flex上有一个简单的逻辑来登录salesforce并创建一条记录。嵌入VF页面时的flex swf在salesforce内部运行良好。但我的要求是在网站页面上显示flex以创建记录。通过公共站点访问时,登录在同一页面上失败。非常感谢任何帮助。

  

<mx:Script>
<![CDATA[
    import com.salesforce.*;
    import com.salesforce.objects.*;
    import com.salesforce.results.*;
    import mx.controls.Alert;
        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] public var sfdc:Connection = new Connection();

    private function login():void {
        Security.loadPolicyFile("https://salesforce.com/services/Soap/u/crossdomain.xml");

        var lr:LoginRequest = new LoginRequest();
        sfdc.protocol = "https";
        sfdc.serverUrl = "https://login.salesforce.com/services/Soap/u/14.0";
    lr.username = "uname.com";
                           lr.password = "pwdsectoken"; 


        lr.callback = new AsyncResponder(loginSuccess, loginFault);


        sfdc.login(lr);

    }

    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;

        aSo.push(so);

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

    }

    private function loginSuccess(result:Object):void {
         Alert.show("Done");
        contactForm.enabled = true;
    }

    private function sfdcFailure(fault:Object):void {
        Alert.show(fault.faultstring);
    }

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

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

我做错了什么。我已将crossdeomain.xml放在bin / libs / html模板文件夹中。是否需要任何远程站点设置?

0 个答案:

没有答案