SalesForce

Force Client

The PerigeeSalesForceClient is an easy to use implementation on top of NetCoreForce that allows you to connect and authorize easily. It manages the token refreshes and local disk persistence as well as provides several additional methods for easy communication to SalesForce.

Authorization

There are two ways to authorize and keep the connection automatically active.

  • The Consumer Key and Consumer Secret are from the connected application

  • Username (or password if using UserPass flow) are the login user details

  • If using JWT, you'll supply the Certificate and optional password that was uploaded to the connected application

//Username Password
var client = PerigeeSalesForceClient.UsernamePassword(
consumerKey, consumerSecret, 
user, pass);

//JWT
var client = PerigeeSalesForceClient.JWT(
consumerKey, consumerSecret, 
user, new X509Certificate2("SF.pfx", "ABCD123"), 
"login");

Once connected with either of the two methods mentioned above, you'll have full access to the available commands!

Connected Applications

To get to the connected applications in SalesForce, go to "Setup => Build => Create => Apps"

  1. Under the "Connected Apps" Create or Edit one

  2. Enter a Name and Contact Email

  3. Click the box: Enable OAuth Settings

  4. Enter a Callback Url, something like: https://login.salesforce.com/services/oauth2/callback

  5. Click Use digital signatures

    1. Upload a certificate (.cer file) (it can be self-signed)

    2. One option for creating a certificate is the Java Key Tool.

    3. Perigee ships with a CertGen as well, code is linked below

  6. Add Selected OAuth Scopes.

    1. An example of these scopes might be:

      1. full

      2. api

      3. refresh_token,offline_access

  7. Click Save

  8. There's a button called: "Manage Consumer Details" - This will show your consumer key and consumer secret. Store them.

  9. Click the "Manage" button at the top of the connected app, and then "Edit policies"

    1. Setup the polices as you need.

    2. An example of this would be:

      1. Permitted Users: "Admin Approved users are pre-authorized"

      2. IP Relaxation: "Relax IP restrictions"

To create a self signed cert that is valid for 5 years using Perigee:

Examples

Our little demo model class is available here. As you can see, we've used Newtonsoft to remap "Name" to "AccountName".

Describe an SObject

To perform a single describe call:

Get Objects

There are a bunch of ways to get objects, including Querying for them. You may also supply direct IDS in a few ways as well:

If you're going to be calling the auto-mapped version frequently, please cache the map results and supply them to the GetObjectsAsync call as shown:

Watch for changes

We provide an asynchronous block that automatically does all the date time handling, offsets, delays, authentication paramaters, etc. You can easily start or stop this process and it will pick up from the last set of records that were sent through.

Helper watch method

To add a watch directly from Perigee Startup as a Managed Thread:

Update a record

There are two easy ways to update a single record

Query + SOQL

To execute a query, simply supply the query along with a class to map back to:

Many other methods

For the full list of methods and other ways of working with SalesForce, please visit the GitHub page!

Last updated