windows phone 7 个适用于 Salesforce 的应用程序

windows phone 7 app for Salesforce

我想开发 windows phone 7 个用于从 salesforce 执行 crud(创建、检索、更新、删除)操作的应用程序。我使用 developerforce 工具包在 windows 8 和 8.1 中成功完成了一个示例应用程序。但是对于 windows phone 7 我什至没有得到工具包。请任何人帮助我继续开发 windows phone 7 应用程序。提前致谢。

正在使用 developerforce/Force.com-Toolkit-for-NET

您可以通过安装以下 DeveloperForce NuGet 包立即试用这些库。

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

用户名-密码认证流程:- 只需提供您的消费者密钥、消费者秘密、用户名和密码。

var auth = new AuthenticationClient();

await auth.UsernamePasswordAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURUSERNAME", "YOURPASSWORD");

Web 服务器身份验证流程:-

 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);

创建 ForceClient 或 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);

示例:-

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);