GithubHelp home page GithubHelp logo

dbpullman / salesforcesharper Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 372 KB

A lightweight, asynchronous REST client for Salesforce

License: GNU General Public License v3.0

C# 100.00%
salesforce salesforce-rest-api csharp dotnet dotnet-standard

salesforcesharper's Introduction

SalesforceSharper

SalesforceSharper is a light-weight, easy to use asynchronous REST client for Salesforce written in .NET.

Installing

To add SalesforceSharper to your project, use the Nuget package on Nuget.org

https://www.nuget.org/packages/SalesforceSharper/

Usage

To use SalesforceSharper, you must authenticate before making any other method calls:

Note: Your password is a combination of your user password and security token

var auth = new UsernamePasswordAuthenticator("<ConsumerKey>",
                "<ConsumerSecret>",
                "<Username>",
                "<Password><SecurityToken>");

var authInfo = await auth.Authenticate();

var client = new SalesforceClient(authInfo.InstanceUrl, authInfo.AccessToken);

After authenticated, you can begin to use the client:

Query

The query method will return 2000 records matching a query. To query more than 2000 records, us the QueryAll<>() method (example below)

var accounts = await client.Query<Account>("SELECT Id, Name FROM Account");

Query All

The query all functionality will query all records (or the specified records in the LIMIT clause) and return more than 2000 records.

var accounts = await client.QueryAll<Account>("SELECT Id, Name FROM Account");

Create

To create a record:

var acct = new Account()
{
  Name = "Test Account"
};

var createdAccount = await client.Create<Account>(acct);

or

var createdAccount = await client.Create("Account", acct);

Update

To update a record:

var updatedAccount = new Account()
{
  Name = "Updated Test Account"
};

var updated = await client.Update<Account>("<recordId>", updatedAccount);

or

var updated = await client.Update("Account", "<recordId>", updatedAccount);

Delete

To delete a record:

var deleted = await client.Delete<Account>("<recordId>");

or

var deleted = await client.Delete("Account", "<recordId>");

Attribute Usage

There is a SalesforceObjectAttribute that can be used to name a class to match the object name in Salesforce. This is used in the Update, Create, and Delete methods to determine the object name and URL:

[SalesforceObject("Custom_Object__c")]
public class CustomObject
{
  public string Id { get; set; }
  public string Name { get; set; }
}

var customObj = new CustomeObject()
{
  Id = "1234567891011",
  Name = "Custom Object Name"
};

var created = await client.Create<CustomObject>(customObj);

The above method call would result in the following URL being used to make the API call /services/data/v45.0/Custom_Object__c

This allows you to name your objects what you want on the client side and helps keep the client side code cleaner and more readable.

salesforcesharper's People

Contributors

dbpullman avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.