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 ¶
- Variables
- type Client
- func (client *Client) AttachFile(targetID, filename string, data io.Reader) (res *Response, err error)
- func (client *Client) CreateObject(name string, object interface{}) (interface{}, error)
- func (c *Client) Do(req *http.Request, value interface{}) error
- func (client *Client) GetObjectByExtID(name, externalIDField, id string) (interface{}, error)
- func (client *Client) GetObjectByID(name, id string) (interface{}, error)
- func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)
- func (client *Client) UpdateObjectByExtID(name, externalIDField, id string, object interface{}) (interface{}, error)
- func (client *Client) UpdateObjectByID(name, id string, object interface{}) error
- type Context
- type ErrorResponse
- type Response
- type Specification
Constants ¶
This section is empty.
Variables ¶
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 ¶
CreateObject creates a new sobject of type name with the contents of object
func (*Client) Do ¶
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 ¶
GetObjectByExtID returns the sobject of type name given it's id using the externalIDField
func (*Client) GetObjectByID ¶
GetObjectByID returns the sobject of type name given it's id
func (*Client) NewRequest ¶
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 ¶
UpdateObjectByID updates the sobject of type name by id
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.