sfdc

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sfdc provides access to a small set of Salesforce APIs. This package is opinionated and intended for use in containers. It relies on reading environment variables for configuration. Function parameters are strongly typed to enable easier use with https://github.com/google/wire

Index

Constants

This section is empty.

Variables

View Source
var (

	// EnvconfigPrefix is the default prefix for environment variables processed with https://github.com/kelseyhightower/envconfig
	EnvconfigPrefix = "salesforce"
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client used to interact with the Salesforce API

func NewClient

func NewClient(context Context, specification *Specification) (*Client, error)

NewClient creates a new client for Salesforce JSON API access. Currently, only JWT authentication is supported. Specification is filled using environment variables processed with https://github.com/kelseyhightower/envconfig if nil

func (*Client) AttachFile

func (client *Client) AttachFile(targetID, filename string, data io.Reader) (res *Response, err error)

AttachFile creates related file on an sobject with the targetID. The name of the related file comes from filename and the content comes from data.

func (*Client) CreateObject

func (client *Client) CreateObject(name string, object interface{}) (interface{}, error)

CreateObject creates a new sobject of type name with the contents of object

func (*Client) Do

func (c *Client) Do(req *http.Request, value interface{}) error

Do sends an JSON API request to Salesforce. The API response is JSON decoded and stored in the value, or returned as an error if an API error has occurred. If value implements the io.Writer interface, the raw response body will be written to value, without attempting to first decode it. Do will return an ErrorResponse if the Salesforce API responds with any http error.

func (*Client) GetObjectByExtID

func (client *Client) GetObjectByExtID(name, externalIDField, id string) (interface{}, error)

GetObjectByExtID returns the sobject of type name given it's id using the externalIDField

func (*Client) GetObjectByID

func (client *Client) GetObjectByID(name, id string) (interface{}, error)

GetObjectByID returns the sobject of type name given it's id

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the instance URL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) UpdateObjectByExtID

func (client *Client) UpdateObjectByExtID(name, externalIDField, id string, object interface{}) (interface{}, error)

UpdateObjectByExtID updates the sobject of type name by id using the externalIDField

func (*Client) UpdateObjectByID

func (client *Client) UpdateObjectByID(name, id string, object interface{}) error

UpdateObjectByID updates the sobject of type name by id

type Context

type Context context.Context

Context is the context used for http requests made from this package

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Errors   []struct {
		Message   string `json:"message"`
		Errorcode string `json:"errorCode"`
	}
}

ErrorResponse has the details of the SalesForce error as well as the http Response

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Response

type Response struct {
	ID      string        `json:"id"`
	Success bool          `json:"success"`
	Errors  []interface{} `json:"errors"`
}

Response is returned from most operations involving Salesforce sobjects

type Specification

type Specification struct {
	// E.g. https://yourcompany-testinsance.my.salesforce.com
	InstanceURL url.URL `required:"true" split_words:"true"`
	// E.g. https://test.salesforce.com for non-prod or https://login.salesforce.com for prod
	AuthenticationEndpoint url.URL `required:"true" split_words:"true"`
	// E.g. person@example.com
	Username string `required:"true"`
	// E.g. whateverSalesforceGeneratesWhenYouConfigure.JWTAuthenticationFromTheSalesforceAdminUI
	ClientID string `required:"true" split_words:"true"`
	// E.g. secrets/jwt-signing.key
	JWTKeyPath string `required:"true" split_words:"true"`
}

Specification is the environment configuration for the client. This is processed with https://github.com/kelseyhightower/envconfig using EnvconfigPrefix for the prefix.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL