Search code examples
windows-phonesalesforce

windows phone 7 app for Salesforce


I want to develop windows phone 7 app for doing crud(Create, Retrieve, Update, Delete) operations from salesforce. I'm successfully done an sample app in windows 8 and 8.1 using developerforce toolkit. But for windows phone 7 i'm not getting even toolkit also. Please any one help me for moving forward in developing windows phone 7 app. Thanks in advance.


Solution

  • Using developerforce/Force.com-Toolkit-for-NET

    You can try the libraries immmediately by installing the following DeveloperForce NuGet packages.

    Install-Package DeveloperForce.Force
    Install-Package DeveloperForce.Chatter
    

    Username-Password Authentication Flow:- Simply provide your consumer key, consumer secret, username, and password.

    var auth = new AuthenticationClient();
    
    await auth.UsernamePasswordAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURUSERNAME", "YOURPASSWORD");
    

    Web-Server Authentication Flow:-

     var url =
            Common.FormatAuthUrl(
                "https://login.salesforce.com/services/oauth2/authorize", // if using sandbox org then replace login with test
                ResponseTypes.Code,
                "YOURCONSUMERKEY",
                HttpUtility.UrlEncode("YOURCALLBACKURL"));
    await auth.WebServerAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURCALLBACKURL", code);
    

    Creating the ForceClient or BulkForceClient:-

    var instanceUrl = auth.InstanceUrl;
    var accessToken = auth.AccessToken;
    var apiVersion = auth.ApiVersion;
    
    var client = new ForceClient(instanceUrl, accessToken, apiVersion);
    var bulkClient = new BulkForceClient(instanceUrl, accessToken, apiVersion);
    

    Example:-

    var instanceUrl = auth.InstanceUrl;
    var accessToken = auth.AccessToken;
    var apiVersion = auth.ApiVersion;
    
    var client = new ForceClient(instanceUrl, accessToken, apiVersion);
    var bulkClient = new BulkForceClient(instanceUrl, accessToken, apiVersion);
    ```
    
    ### Sample Code
    
    Below you'll find a few examples that show how to use the toolkit.
    
    #### Create
    
    You can create with the following code:
    
    ```
    public class Account
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
    
    ...
    
    var account = new Account() { Name = "New Account", Description = "New Account Description" };
    var id = await client.CreateAsync("Account", account);
    ```
    
    You can also create with a non-strongly typed object:
    
    ```
    var client = new ForceClient(_consumerKey, _consumerSecret, _username, _password);
    var account = new { Name = "New Name", Description = "New Description" };
    var id = await client.CreateAsync("Account", account);
    ```
    
    #### Update
    
    You can update an object:
    
    ```
    var account = new Account() { Name = "New Name", Description = "New Description" };
    var id = await client.CreateAsync("Account", account);
    
    account.Name = "New Name 2";
    
    var success = await client.UpdateAsync("Account", id, account);
    ```
    
    #### Delete
    
    You can delete an object:
    
    ```
    var account = new Account() { Name = "New Name", Description = "New Description" };
    var id = await client.Create("Account", account);
    var success = await client.DeleteAsync("Account", id)
    ```
    
    #### Query
    
    You can query for objects:
    
    
    ```
    public class Account
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
    
    ...
    
    var accounts = await client.QueryAsync<Account>("SELECT id, name, description FROM Account");
    
    foreach (var account in accounts.records)
    {
        Console.WriteLine(account.Name);
    }
    ```
    
    ### Bulk Sample Code
    
    Below are some simple examples that show how to use the ```BulkForceClient```
    
    **NOTE:** The following features are currently not supported
    
    * CSV data type requests / responses
    * Zipped attachment uploads
    * Serial bulk jobs
    * Query type bulk jobs
    
    #### Create
    
    You can create multiple records at once with the Bulk client:
    
    ```
    public class Account 
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
    
    ...
    
    var accountsBatch1 = new SObjectList<Account>
    {
        new Account {Name = "TestStAccount1"},
        new Account {Name = "TestStAccount2"}
    };
    var accountsBatch2 = new SObjectList<Account>
    {
        new Account {Name = "TestStAccount3"},
        new Account {Name = "TestStAccount4"}
    };
    var accountsBatch3 = new SObjectList<Account>
    {
        new Account {Name = "TestStAccount5"},
        new Account {Name = "TestStAccount6"}
    };
    
    var accountsBatchList = new List<SObjectList<Account>> 
    { 
        accountsBatch1,
        accountsBatch2,
        accountsBatch3
    };
    
    var results = await bulkClient.RunJobAndPollAsync("Account", 
                            Bulk.OperationType.Insert, accountsBatchList);
    ```
    
    The above code will create 6 accounts in 3 batches. Each batch can hold upto 10,000 records and you can use multiple batches for Insert and all of the operations below.
    For more details on the Salesforce Bulk API, see [the documentation](https://resources.docs.salesforce.com/196/latest/en-us/sfdc/pdf/api_asynch.pdf "Salesforce Bulk API Docs").
    
    You can also create objects dynamically using the inbuilt SObject class:
    
    ```
    var accountsBatch1 = new SObjectList<SObject>
    {
        new SObject 
        {
            {"Name" = "TestDyAccount1"}
        },
        new SObject 
        {
            {"Name" = "TestDyAccount2"}
        }
    };
    
    var accountsBatchList = new List<SObjectList<SObject>> 
    { 
        accountsBatch1
    };
    
    var results = await bulkClient.RunJobAndPollAsync("Account", 
                            Bulk.OperationType.Insert, accountsBatchList);
    
    ```
    
    #### Update
    
    Updating multiple records follows the same pattern as above, just change the ```Bulk.OperationType``` to ```Bulk.OperationType.Update```
    
    ```
    var accountsBatch1 = new SObjectList<SObject>
    {
        new SObject 
        {
            {"Id" = "YOUR_RECORD_ID"},
            {"Name" = "TestDyAccount1Renamed"}
        },
        new SObject 
        {
            {"Id" = "YOUR_RECORD_ID"},
            {"Name" = "TestDyAccount2Renamed"}
        }
    };
    
    var accountsBatchList = new List<SObjectList<SObject>> 
    { 
        accountsBatch1
    };
    
    var results = await bulkClient.RunJobAndPollAsync("Account", 
                            Bulk.OperationType.Update, accountsBatchList);
    
    ```
    
    #### Delete
    
    As above, you can delete multiple records with ```Bulk.OperationType.Delete```
    
    ```
    var accountsBatch1 = new SObjectList<SObject>
    {
        new SObject 
        {
            {"Id" = "YOUR_RECORD_ID"}
        },
        new SObject 
        {
            {"Id" = "YOUR_RECORD_ID"}
        }
    };
    
    var accountsBatchList = new List<SObjectList<SObject>> 
    { 
        accountsBatch1
    };
    
    var results = await bulkClient.RunJobAndPollAsync("Account", 
                            Bulk.OperationType.Delete, accountsBatchList);