LogoLogo
HomePricingDocumentation
  • 💿Getting Started
    • Installation and Project Setup
    • Hello Perigee!
    • Perigee Application Design
    • Hello Configuration
    • Hello Logs
    • Hello Integration
    • Troubleshooting
    • Case Studies
  • 📃License + Notice
    • 📂Licensing
    • Notice of Third Party Agreements
  • 🚀Perigee and Beyond
    • Extending - Threads
    • Extending - Loaders
    • ⏳All about CRON
  • 🔮API Generation
    • What is API Generation?
    • API Builder
  • 🗺️Architecting YOUR App
    • Design and Requirements
    • Define Sources
    • Requirements
  • 🧩Core Modules
    • 🌐PerigeeApplication
    • 🪡Thread Registry
    • Event Sources
      • Scheduled/Logic
        • CRON Thread
        • Scheduler
        • Sync Agent
      • Watchers
        • SalesForce
        • Sharepoint
        • Directory Watch
        • Directory Notifier
        • IMAP
    • Credential Management
      • Connection Strings
      • Custom Refresh Logic
      • RestSharp Authenticator
      • Credential Store SDK
      • ⁉️Troubleshooting Credentials
    • Integration Utilities
      • HTTP(S) - RestSharp
      • Transaction Coordinator
      • Limiter
      • Watermarking
    • Alert Managers
      • SMS
      • Email
      • Discord
      • Teams
    • File Formats
      • Excel
      • CSV
    • 📁File System Storage
      • File Revision Store
      • Concurrent File Store
      • FileSync + Cache
    • Third Party
      • SmartSheets
      • Microsoft Graph
    • Perigee In Parallel
      • Parallel Processing Reference
      • Extensions
      • GroupProcessor
      • SingleProcessor
    • 🧱Utility Classes
      • Metrics
      • F(x) Expressions
      • Multi-Threaded Processor (Scatter Gather)
      • OpenAI - GPT
      • XML Converter
      • Dynamic Data Table
      • Debounce
      • Thread Conditions
      • Perigee Utility Class
      • Network Utility
      • Lists
      • FileUtil
      • Inclusive2DRange
      • Strings, Numbers, Dates
      • Nested Sets
      • Behavior Trees
      • JsonCompress
      • Topological Sorting
      • DBDownloader
    • 🈁Bit Serializer
  • 📣Examples and Demos
    • API + Perigee
    • 📰Excel Quick Load
    • SalesForce Watcher
    • Report Scheduler
    • Agent Data Synchronization
    • 📩IMAP Echo bot
    • Watch and load CSVs
    • Graph Delegated Authorization + DataVerse
    • Coordinator Demo
    • Azure Service Bus
    • QuickBooks Online
  • 📘Blueprints
    • Perigee With .NET Hosting
    • Web Host Utilities
    • 🔌Plugin Load Context
  • 🎞️Transforms
    • 🌟What is Transforms?
    • 📘Terminology
    • 🦾The Mapping Document
    • 👾Transformation Process
    • 😎Profile
    • 🎒Automation
      • 🕓Package Options
      • 🔳Configuration
    • 🔧Utilities
      • 🧹Clean
      • 📑Map File
      • 🔎File Identification
      • 🗺️Map Generation
      • 🪅Insert Statement Generation
  • 🗃️Transform SDK
    • 👋Quick Start Guide
    • 🥳MapTo
    • 🔌Authoring Plugins
      • 🔘File IO Process
      • 📢Data Quality
      • 🟢Transform Process
    • SDK Reference
      • 🔘FileIOProcessData
      • 📢DataQualityContext
      • 🎛️TransformDataContext
      • 🏅TransformResult
Powered by GitBook
On this page
  • Force Client
  • Authorization
  • Connected Applications
  • Examples
  • Describe an SObject
  • Get Objects
  • Watch for changes
  • Update a record
  • Query + SOQL
  • Many other methods
Export as PDF
  1. Core Modules
  2. Event Sources
  3. Watchers

SalesForce

PreviousWatchersNextSharepoint

Last updated 11 months ago

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.

We have used and implemented custom logic into NetCoreForce. To get more information about it's functionality the client documentation can be

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:

var x5 = CertGen2.SelfSigned();
CertGen2.SaveX509ToPath(x5, "C:\\SF", "SF", "ABCDEFG12345");

Examples

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

public class SFAccount
{
    public string id { get; set; }

    [Newtonsoft.Json.JsonProperty("Name")]
    public string AccountName { get; set; }

    public string Type { get; set; }

}

Describe an SObject

To perform a single describe call:

var res = client.GetObjectDescribe("Account").GetAwaiter().GetResult();

Get Objects

//Get a single object by ID, mapped back, supplying the fields
SFAccount byID = client.GetObjectById<SFAccount>("Account", "001f400000Mk8lPAAR", new List<string>() { "id", "name" }).GetAwaiter().GetResult();

//Get a list of objects by ID, dynamically automapped from your class to SalesForce
List<SFAccount> objectsByID = client.GetObjectsAsync<SFAccount>("Account", new List<string>() { "001f400000Mk8lPAAR", "001f400001N4NXqAAN" }).GetAwaiter().GetResult();

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:

//Store the cache somewhere static
var CachedProperties = client.MapProperties<SFAccount>("Account").Values.ToList();

//Supply cache map on frequent and subsequent calls
List<SFAccount> objectsByID = client.GetObjectsAsync<SFAccount>("Account", new List<string>() { "001f400000Mk8lPAAR", "001f400001N4NXqAAN" }, CachedProperties).GetAwaiter().GetResult();

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.

client.WatchAsync<SFAccount>("Account", CTS.Token, (ct, updated, deleted) => {
    
    //updated records, bound back to an SFAccount class
    foreach (var item in updated) { 
        Console.WriteLine($"[{item.id}] {item.AccountName}({item.Type})"); }
        
    //Deleted ID's, along with the deleted date
    foreach (var item in deleted) { 
        Console.WriteLine($"{item.id} - {item.deletedDate:G}"); }
        
}).GetAwaiter().GetResult();

Helper watch method

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

PerigeeApplication.ApplicationNoInit("SalesForce Demo", (c) => {

    c.AddSalesForceWatch<SFAccount>("WatchAccounts", "Account", cKey, cSec, sUser, x5092Cert, "login", 
    (ct, log, updated, deleted) => {

        //updated records, bound back to an SFAccount class
        foreach (var item in updated)
        {
            Console.WriteLine($"[{item.id}] {item.AccountName}({item.Type})");
        }

        //Deleted ID's, along with the deleted date
        foreach (var item in deleted)
        {
            Console.WriteLine($"{item.id} - {item.deletedDate:G}");
        }

    });

});

Make sure to configure your own:

  • Certificate

  • Consumer key

  • Consumer secret

  • User

  • Domain

Update a record

There are two easy ways to update a single record

//Update by bound object properties, serialized through newtonsoft
client.UpdateRecord<SFAccount>("Account", "001f400000Mk8lPAAR", new SFAccount() { Type = "Prospect" }).GetAwaiter().GetResult();

//Supply a dyanamic object or class, unbound
client.UpdatePatch("Account", "001f400000Mk8lPAAR", new { Rating = "Warm" }).GetAwaiter().GetResult();

Query + SOQL

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

var accounts = client.Query<SFAccount>("SELECT id,name from account limit 10").GetAwaiter().GetResult();

Many other methods

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

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

🧩
found here
GitHub page
Querying
See the Authorization section above