### Install DeveloperForce NuGet Packages Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md This section provides commands to install the DeveloperForce.Force and DeveloperForce.Chatter libraries using both Package Manager (NuGet) and .NET CLI. These packages provide the core functionality for interacting with Force.com and Chatter APIs, enabling developers to quickly integrate Salesforce capabilities into their .NET applications. ```PowerShell Install-Package DeveloperForce.Force Install-Package DeveloperForce.Chatter ``` ```cmd dotnet add package DeveloperForce.Force dotnet add package DeveloperForce.Chatter ``` -------------------------------- ### Query Salesforce Object Metadata with C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to retrieve metadata for a Salesforce object, such as 'Account', using `DescribeAsync`. The example shows how to access field labels from the returned JSON object, providing insights into object structure. ```cs var describe = await client.DescribeAsync("Account"); foreach (var field in (JArray)describe["fields")) { Console.WriteLine(field["label"]); } ``` -------------------------------- ### Initialize ForceClient and BulkForceClient in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to instantiate ForceClient and BulkForceClient instances after successful authentication. These clients use the obtained instance URL, access token, and API version to interact with the Force.com REST APIs, enabling standard and bulk data operations respectively. ```C# 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); ``` -------------------------------- ### Create Salesforce Account with Strongly Typed C# Object Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to create a new Salesforce Account record using a strongly typed C# `Account` class and the `CreateAsync` method. This approach provides type safety and clear property definitions for object mapping. ```cs 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); ``` -------------------------------- ### Bulk Create Salesforce Accounts with Strongly Typed C# Objects Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Illustrates how to perform a bulk insert of multiple Salesforce Account records using the `BulkForceClient`. It demonstrates creating batches of strongly typed `Account` objects and running an insert job for efficient, large-scale data creation. ```cs public class Account { public string Id { get; set; } public string Name { get; set; } public string Description { get; set; } } var accountsBatch1 = new SObjectList { new Account {Name = "TestStAccount1"}, new Account {Name = "TestStAccount2"} }; var accountsBatch2 = new SObjectList { new Account {Name = "TestStAccount3"}, new Account {Name = "TestStAccount4"} }; var accountsBatch3 = new SObjectList { new Account {Name = "TestStAccount5"}, new Account {Name = "TestStAccount6"} }; var accountsBatchList = new List> { accountsBatch1, accountsBatch2, accountsBatch3 }; var results = await bulkClient.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert, accountsBatchList); ``` -------------------------------- ### Bulk Create Salesforce Accounts with Dynamically Typed C# Objects Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Shows how to perform a bulk insert of multiple Salesforce Account records using dynamically typed `SObject` instances. This provides flexibility for creating records without predefined C# classes, allowing for dynamic schema handling. ```cs var accountsBatch1 = new SObjectList { new SObject { {"Name" = "TestDyAccount1"} }, new SObject { {"Name" = "TestDyAccount2"} } }; var accountsBatchList = new List> { accountsBatch1 }; var results = await bulkClient.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert, accountsBatchList); ``` -------------------------------- ### Bulk Update Salesforce Accounts with C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to perform a bulk update of multiple Salesforce Account records. It shows how to prepare batches of `SObject` instances with record IDs and updated fields, then execute an update job using `BulkConstants.OperationType.Update`. ```cs var accountsBatch1 = new SObjectList { new SObject { {"Id" = "YOUR_RECORD_ID"}, {"Name" = "TestDyAccount1Renamed"} }, new SObject { {"Id" = "YOUR_RECORD_ID"}, {"Name" = "TestDyAccount2Renamed"} } }; var accountsBatchList = new List> { accountsBatch1 }; var results = await bulkClient.RunJobAndPollAsync("Account", BulkConstants.OperationType.Update, accountsBatchList); ``` -------------------------------- ### Update Salesforce Account with C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Illustrates how to update an existing Salesforce Account record. It first creates an account, then modifies its properties, and finally uses the `UpdateAsync` method to persist the changes to Salesforce. ```cs 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); ``` -------------------------------- ### Create Salesforce Account with Non-Strongly Typed C# Object Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Shows how to create a new Salesforce Account record using an anonymous, non-strongly typed C# object. This method offers flexibility when a formal class definition is not required, allowing dynamic property assignment. ```cs var client = new ForceClient(_consumerKey, _consumerSecret, _username, _password); var account = new { Name = "New Name", Description = "New Description" }; var id = await client.CreateAsync("Account", account); ``` -------------------------------- ### Query Salesforce Objects with Strongly Typed C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Shows how to query Salesforce objects, specifically Account records, and map them to a strongly typed C# `Account` class. It uses `QueryAsync` to retrieve records based on a SOQL query and then iterates through them. ```cs public class Account { public string Id { get; set; } public string Name { get; set; } public string Description { get; set; } } var accounts = await client.QueryAsync("SELECT id, name, description FROM Account"); foreach (var account in accounts.records) { Console.WriteLine(account.Name); } ``` -------------------------------- ### Initialize AuthenticationClient with Specific API Version in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Shows how to instantiate an AuthenticationClient with a specific Salesforce API version. The default API version is v36.0, but this allows for explicit versioning if required by your application's compatibility needs or to leverage newer API features. ```C# var auth = new AuthenticationClient("v44.0"); ``` -------------------------------- ### Authenticate with Username-Password Flow in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to obtain an access token using the Username-Password Authentication Flow. This method requires providing your consumer key, consumer secret, username, and password concatenated with your API Token. It's a straightforward way to authenticate for applications where user credentials can be securely managed. ```C# var auth = new AuthenticationClient(); await auth.UsernamePasswordAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURUSERNAME", "YOURPASSWORDANDTOKEN"); ``` -------------------------------- ### Bulk Delete Salesforce Accounts with C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Illustrates how to perform a bulk delete of multiple Salesforce Account records. It shows how to prepare batches of `SObject` instances containing only the record IDs and then execute a delete job using `BulkConstants.OperationType.Delete`. ```cs var accountsBatch1 = new SObjectList { new SObject { {"Id" = "YOUR_RECORD_ID"} }, new SObject { {"Id" = "YOUR_RECORD_ID"} } }; var accountsBatchList = new List> { accountsBatch1 }; var results = await bulkClient.RunJobAndPollAsync("Account", BulkConstants.OperationType.Delete, accountsBatchList); ``` -------------------------------- ### Format Authorization URL for Web-Server Flow in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Explains how to construct the authorization URL for the Web Server Authentication Flow. This URL redirects the user to Salesforce for authentication, passing the consumer key and a URL-encoded callback URL. This is the first step in enabling users to authenticate with their own Salesforce credentials. ```C# 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")); ``` -------------------------------- ### Delete Salesforce Account with C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Demonstrates how to delete a Salesforce Account record. It shows the creation of an account followed by its deletion using the `DeleteAsync` method, requiring only the object type and its ID. ```cs var account = new Account() { Name = "New Name", Description = "New Description" }; var id = await client.Create("Account", account); var success = await client.DeleteAsync("Account", id) ``` -------------------------------- ### Retrieve Latest API Version from Force.com in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md Illustrates how to programmatically fetch the latest API version available from your Force.com instance using the AuthenticationClient. This ensures your application is always using the most current API, which can be useful for future-proofing and adapting to platform updates. ```C# var auth = new AuthenticationClient(); await auth.GetLatestVersionAsync(); ``` -------------------------------- ### Request Access Token with Web-Server Flow in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md After a user authenticates via the Web Server Flow and is redirected back to your application, this snippet shows how to use the returned code to request a valid access token. This token is essential for subsequent API calls, allowing your application to interact with Salesforce on behalf of the authenticated user. ```C# await auth.WebServerAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURCALLBACKURL", code); ``` -------------------------------- ### Perform Bulk Upsert Operation with External ID in C# Source: https://github.com/wadewegner/force.com-toolkit-for-net/blob/master/README.md This C# code demonstrates how to perform a bulk upsert operation on Salesforce Account records using the Force.com Toolkit for .NET. It leverages a custom 'External Id' field (e.g., 'ExampleId') to update or insert records, showing how to prepare batches of SObjects and execute the job asynchronously via the bulk client. ```C# // Assumes you have a custom field "ExampleId" on your Account object // that has the "External Id" flag set. var accountsBatch1 = new SObjectList { new SObject { {"Name" = "TestDyAccount1"}, {"ExampleId" = "ID00001"} }, new SObject { {"Name" = "TestDyAccount2"}, {"ExampleId" = "ID00002"} } }; var accountsBatchList = new List> { accountsBatch1 }; var results = await bulkClient.RunJobAndPollAsync("Account", "ExampleId" BulkConstants.OperationType.Upsert, accountsBatchList); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.