- Notifications
You must be signed in to change notification settings - Fork68
Salesforce REST API toolkit for .NET Standard and .NET Core
License
anthonyreilly/NetCoreForce
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project is not offered, sponsored, or endorsed by Salesforce.
The primary target is .NET Standard 2.0 to provide the widest possible support.
- .NET Standard 2.0 for widest possible support including .NET Framework 4.6.1+ and .NET Core 2.0
- .NET Standard 2.1 for newer .NET Core versions
For more info on .NET Standard compatiblitysee the Microsoft documentation here
Full target list
- .NET Standard 2.0
- .NET Standard 2.1
- .NET Core 3.1
- .NET 5.0
- .NET 6.0
- .NET 7.0
- .NET 8.0
- .NET 9.0
- .NET Framework 4.6.2
- .NET Framework 4.7.2
- .NET Framework 4.8
All possible frameworks are specifically targeted so that conditional compilation can be done where required.
Full tested support is for .NET Core 6.0 - 9.0 as tooling and tests target those.
Legacy .NET Frameworks are partially tested
- NetCoreForce.Client
- Main library
- NetCoreForce.Client.Tests
- Unit tests (offline/mocked)
- NetCoreForce.FunctionalTests
- Online Unit tests (Needs valid login credentials)
- NetCoreForce.ModelGenerator
- CheckREADME for docs
- Optional custom dotnet-cli tool for code generation of custom objects/fields.
- NetCoreForce.Models
- CheckREADME for docs
- Optional library with a set of pre-generated standard models
- SampleConsole
- A simple .NET Core console app to demonstrate the library.
- Newtonsoft.Json (JSON Serialization)
- System.Text.Encodings.Web (URL formatting)
- Microsoft.Bcl.AsyncInterfaces
- Only included in .netstandard2.0, .netcoreapp2.0 targets
- Provides await using, async disposables
(Migration from Newtonsoft.Json to System.Text.Json is planned)
Feedback and suggestions welcome.
Licensed under the MIT license.
///Initialize the authentication clientAuthenticationClientauth=newAuthenticationClient();//Pass in the login informationawaitauth.UsernamePasswordAsync("your-client-id","your-client-secret","your-username","your-password","token-endpoint-url");//the AuthenticationClient object will then contain the instance URL and access token to be used in each of the API callsForceClientclient=newForceClient(auth.AccessInfo.InstanceUrl,auth.ApiVersion,auth.AccessInfo.AccessToken);//Retrieve an object by IdSfAccountacct=awaitclient.GetObjectById<SfAccount>(SfAccount.SObjectTypeName,"001i000002C8QTI");//Modify the record and updateacct.Description="Updated Description";awaitclient.UpdateRecord<SfAccount>(SfAccount.SObjectTypeName,acct.Id,acct);//Delete the recordawaitclient.DeleteRecord(SfAccount.SObjectTypeName,acct.Id);//Get the results of a SOQL queryList<SfCase>cases=awaitclient.Query<SfCase>("SELECT Id,CaseNumber,Account.Name,Contact.Name FROM Case");
When you include related objects in a SOQL query:
SELECT Id,CaseNumber,Account.Name,Contact.Name FROM CaseAnd get the results via the client, you can then access the related objects and fields included in the query in a fluent manner.
List<SfCase>cases=awaitclient.Query<SfCase>("SELECT Id,CaseNumber,Account.Name,Contact.Name FROM Case");SfCasefirstCase=cases[0];stringcaseNumber=firstCase.CaseNumber;stringcaseAccountName=firstCase.Account.Name;stringcaseContactName=firstCase.Contact.Name;
Nested queries are not fully supported - the subquery results will not be complete if they exceed the batch size as the NextRecordsUrl in the subquery results is not being acted upon. Instead use the relationship syntax in the example above.
// *NOT* fully supported"SELECT Id,CaseNumber, (Select Contact.Name from Account) FROM Case"Query method will retrieve the full result set before returning. By default, results are returned in batches of 2000.In cases where you are working with large result sets, you may want to use QueryAsync to retrieve the batches asynchronously for better performance.
// First create the async enumerable. At this point, no query has been executed.// batchSize can be omitted to use the default (usually 2000), or given a custom value between 200 and 2000.IAsyncEnumerable<SfContact>contactsEnumerable=client.QueryAsync<SfContact>("SELECT Id, Name FROM Contact ",batchSize:200);// Get the enumerator, in a using block for proper disposalawaitusing(IAsyncEnumerator<SfContact>contactsEnumerator=contactsEnumerable.GetAsyncEnumerator()){// MoveNext() will execute the query and get the first batch of results.// Once the inital result batch has been exhausted, the remaining batches, if any, will be retrieved.while(awaitcontactsEnumerator.MoveNextAsync()){SfContactcontact=contactsEnumerator.Current;// process your results}}
About
Salesforce REST API toolkit for .NET Standard and .NET Core
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.