/go-salesforce-sdk

Unofficial SDK for the Salesforce REST API

Primary LanguageGoMIT LicenseMIT

Tests

Go Salesforce SDK

go-salesforce-sdk is an unofficial SDK for the Salesforce REST API.

Checkout our release notes for information about the latest bug fixes, updates, and features added to the sdk.

Jump To:

Installation

This SDK comes in two parts: a CLI for generating types and running small commands, and a series of Go packages intended to be used as a library in your applications.

# install the package using go modules
go get github.com/beeekind/go-salesforce-sdk
# install the CLI
go install $GOPATH/src/github.com/beeekind/go-salesforce-sdk/cmd/go-salesforce-sdk

Examples

This SDK consists of a high level and a low level API. The high level API can be found in the root package while all other packages should be considered low level.

We recommend you actually use the low level API as it is much more configurable and still simple to use.

Use these examples, all *_test.go files, the root package, and the godoc, as documentation for using this SDK.

  1. Authenticate via the Password or JWT flows by setting environmental variables:
# For the JWT flow (recommended):
# https://mannharleen.github.io/2020-03-03-salesforce-jwt/

export SALESFORCE_SDK_CLIENT_ID=...
export SALESFORCE_SDK_USERNAME=...
export SALESFORCE_SDK_PEM_PATH=...

#For the Password Flow:

export SALESFORCE_SDK_CLIENT_ID=...
export SALESFORCE_SDK_CLIENT_SECRET=...
export SALESFORCE_SDK_USERNAME=...
export SALESFORCE_SDK_PASSWORD=...
export SALESFORCE_SDK_SECURITY_TOKEN=...
  1. Generate the types you intend to use
go-salesforce-sdk generate Lead ./ leads 0
  1. Use the SDK
import (
    sdk "github.com/beeekind/go-salesforce-sdk"
    "github.com/beeekind/go-salesforce-sdk/requests"
    "github.com/beeekind/go-salesforce-sdk/soql"
    "github.com/beeekind/go-salesforce-sdk/types"
    "github.com/your/project/leads"
)

type LeadsResponse struct {
    types.QueryResponse
    Records []*leads.Lead `json:"records"`
}

func main(){
    var response LeadsResponse
    _, err := requests. 
        Sender(sdk.DefaultClient).
        URL("query").
        SQLizer(soql.
            Select("Id", "Name", "CreatedDate"). 
            From("Lead"). 
            Limit(100)).
        JSON(&response)

    for _, lead := range response.Records {
        // ...
    }
}

Features


  • Generate type definitions

    • Standard Objects
    • Tooling Objects
  • Authentication Mechanisms

    • JWT flow (recommended)
    • Password flow
  • Concurrent Processing

    • Pre-compute paginated resources for retrieving all paginated records quickly
  • HTTP Client Wrapper

    • HttpTransport customization
    • Ratelimiting
    • GZIP compression
  • Querybuilder (based on squirrel)

    • Select
    • Where
      • Equality | Inequality
      • Subqueries
      • Like | NotLike
      • GT | LT | GTE | LTE
      • Conjugations (And | Or)
    • Group By
    • Order By(s)
    • Limit
    • Offset
    • Prefixes
    • Suffixes
  • Request Builder

    • URL composition
    • Method
    • URL parameters
    • Headers
    • SOQL embeding
    • Build as http.Response
    • Unmarshal into struct
    • application/x-www-form-urlencoded submissions
  • Custom Types

    • Nullable (bool | string | int | float)
    • Date / Datetime
    • Address
    • AlmostBool
  • Metadata Response Types

    • /describe
    • /describe/{objectName}
    • Limits
    • Query
    • Tooling/query
  • Bulk API v2

    • Ingest
    • Query
  • Composite

    • Create
    • Read
    • Update
    • Delete
  • Tree

    • ParseNode(typeDefinition)
    • Recursive object nesting
  • Execute Anonymous Apex

    • SingleEmailMessage
  • And much more...

Packages

Package Link Description
go-salesforce-sdk Link Root package with high level API methods. Other packages should be considered the low-level API
cmd/go-salesforce-sdk Link CLI for generating golang type definitions
apex Link Demonstrates using the Execute Anonymous Apex endpoint to send an email
bulk Link Methods for bulk uploading and retrieving objects as text/csv
client Link Wraps http.Client and provides authentication, ratelimiting, and http.Transport customization
composite Link Provides Create, Read, Update, and Delete, operations with the Composite API
metadata Link TBD
requests Link HTTP request building using the builder design pattern
soql Link SOQL (Salesforce Object Query Language) building using the builder design pattern
templates Link Templates for generating Type definitions, Response types, Apex code, and other artifacts
tree Link Tree API operations for saving nested objects based on their relations. Uses generated types.
types Link Type definitions for Salesforce specific types like Date and Datetime

Contribute

Issues and Pull Requests welcome!

Credits

Gophers Slack.

The greater Devops community for keeping me sane through COVID.