Salesforce xamarin Mobile SDK throwing error “the remote server returned bad request(400)”when query

I’m developing an xamarin based mobile POC for salesforce. Which uses salesforce xamarin mobile SDK component with latest version (1.4.4.0) . Able to login successfully to the salesforce after that queries to SObjects are failing with below error
“remote server returned an error BAD request(400)”…
Below is the code snippet…
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

        Client = new SalesforceClient (Key, Secret, redirectUrl);
        Client.AuthenticationComplete += (sender, e) => OnAuthenticationCompleted (e);

        var users = Client.LoadUsers ();

        if (!users.Any()) {

            var intent = Client.GetLoginInterface () as Intent;
            StartActivityForResult (intent, 42);
        } else {


            LoadAccounts();
        }

        ListView.ItemClick += (sender,e) => {
            var t = ((DataAdapter)ListAdapter)[e.Position];

            System.Diagnostics.Debug.WriteLine("Clicked on " + t.ToString());

            var intent = new Intent();
            intent.SetClass(this, typeof(DetailActivity));
            intent.PutExtra("JsonItem", "{\"attributes\": {\"type\": \"Account\", \"url\": \"/services/data/v28.0/sobjects/Account/\"}, " + 
                string.Format ("\"Id\": \"{0}\", \"Name\": \"{1}\", \"AccountNumber\": \"{2}\", \"Phone\": \"{3}\", \"Website\": \"{4}\", \"Industry\": \"{5}\"", t.Id, t.Name, t.AccountNumber, t.Phone, t.Website, t.Industry) + "}");

            StartActivity(intent);
        };
    }

    void OnAuthenticationCompleted (AuthenticatorCompletedEventArgs e)
    {
        if (!e.IsAuthenticated) {
            // TODO: Handle failed login scenario by re-presenting login form with error
            throw new Exception ("Login failed and we don't handle that.");
        }

        //Client.CurrentUser = users.FirstOrDefault();
        LoadAccounts ();

        Account = e.Account;
        Client.Save (Account);
    }

    async void LoadAccounts ()
    {
        try
        {


            var results = await Client.QueryAsync("SELECT Id, Name, AccountNumber FROM Account");
            var resultRecords = results.Select(s => s.As<AccountObject>()).ToList();
            System.Diagnostics.Debug.WriteLine("records: {0}", resultRecords.Count);
            ListAdapter = new DataAdapter(this, resultRecords);

        }
        catch (WebException ex)
        {

            System.Diagnostics.Debug.WriteLine("Error: ", ex.Message);

        }


    }

Answers

Sign In or Register to comment.