force

package
v0.0.0-...-096e91b Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

A Go package that provides bindings to the force.com REST API

See http://www.salesforce.com/us/developer/docs/api_rest/

Index

Constants

View Source
const (
	BULK_INSERT bulkMode = iota + 1
	BULK_UPDATE
	BULK_UPSERT
	BULK_DELETE
)
View Source
const (
	BaseQueryString = "SELECT %v FROM %v"
)

Variables

This section is empty.

Functions

func BuildQuery

func BuildQuery(fields, table string, constraints []string, constraintJoin string) string

func CreateWithCode

func CreateWithCode(version, clientId, clientSecret, redirectURI, code,
	environment, prefix string, logger ForceApiLogger) (*ForceApi, *ForceOauth, error)

Types

type ApiError

type ApiError struct {
	Fields           []string `json:"fields,omitempty" force:"fields,omitempty"`
	Message          string   `json:"message,omitempty" force:"message,omitempty"`
	ErrorCode        string   `json:"errorCode,omitempty" force:"errorCode,omitempty"`
	ErrorName        string   `json:"error,omitempty" force:"error,omitempty"`
	ErrorDescription string   `json:"error_description,omitempty" force:"error_description,omitempty"`
}

func (ApiError) Error

func (e ApiError) Error() string

func (ApiError) String

func (e ApiError) String() string

func (ApiError) Validate

func (e ApiError) Validate() bool

type ApiErrors

type ApiErrors []*ApiError

Custom Error to handle salesforce api responses.

func (ApiErrors) Error

func (e ApiErrors) Error() string

func (ApiErrors) String

func (e ApiErrors) String() string

func (ApiErrors) Validate

func (e ApiErrors) Validate() bool

type ChildRelationship

type ChildRelationship struct {
	Field               string `json:"field"`
	ChildSObject        string `json:"childSObject"`
	DeprecatedAndHidden bool   `json:"deprecatedAndHidden"`
	CascadeDelete       bool   `json:"cascadeDelete"`
	RestrictedDelete    bool   `json:"restrictedDelete"`
	RelationshipName    string `json:"relationshipName"`
}

type CloseJobRequest

type CloseJobRequest struct {
	State string `json:"state,omitempty"`
}

Response recieved from force.com API after insert of an sobject.

type CreateBatchResponse

type CreateBatchResponse struct {
	ApexProcessingTime      int    `json:"apexProcessingTime"`
	APIActiveProcessingTime int    `json:"apiActiveProcessingTime"`
	CreatedDate             string `json:"createdDate"`
	ID                      string `json:"id"`
	JobID                   string `json:"jobId"`
	NumberRecordsFailed     int    `json:"numberRecordsFailed"`
	NumberRecordsProcessed  int    `json:"numberRecordsProcessed"`
	State                   string `json:"state"`
	SystemModstamp          string `json:"systemModstamp"`
	TotalProcessingTime     int    `json:"totalProcessingTime"`
	StateMessage            string `json:"stateMessage"`
}

type CreateJobRequest

type CreateJobRequest struct {
	Operation   string `json:"operation,omitempty"`
	Object      string `json:"object,omitempty"`
	ContentType string `json:"contentType,omitempty"`
}

Response recieved from force.com API after insert of an sobject.

type CreateJobResponse

type CreateJobResponse struct {
	ApexProcessingTime      int     `json:"apexProcessingTime"`
	APIActiveProcessingTime int     `json:"apiActiveProcessingTime"`
	APIVersion              float64 `json:"apiVersion"`
	ConcurrencyMode         string  `json:"concurrencyMode"`
	ContentType             string  `json:"contentType"`
	CreatedByID             string  `json:"createdById"`
	CreatedDate             string  `json:"createdDate"`
	ID                      string  `json:"id"`
	NumberBatchesCompleted  int     `json:"numberBatchesCompleted"`
	NumberBatchesFailed     int     `json:"numberBatchesFailed"`
	NumberBatchesInProgress int     `json:"numberBatchesInProgress"`
	NumberBatchesQueued     int     `json:"numberBatchesQueued"`
	NumberBatchesTotal      int     `json:"numberBatchesTotal"`
	NumberRecordsFailed     int     `json:"numberRecordsFailed"`
	NumberRecordsProcessed  int     `json:"numberRecordsProcessed"`
	NumberRetries           int     `json:"numberRetries"`
	Object                  string  `json:"object"`
	Operation               string  `json:"operation"`
	State                   string  `json:"state"`
	SystemModstamp          string  `json:"systemModstamp"`
	TotalProcessingTime     int     `json:"totalProcessingTime"`
}

type ForceApi

type ForceApi struct {
	OAuth *ForceOauth
	// contains filtered or unexported fields
}

func CreateWithAccessToken

func CreateWithAccessToken(version, clientId, clientSecret, accessToken, refreshToken, instanceUrl string) (*ForceApi, error)

func CreateWithRefreshToken

func CreateWithRefreshToken(version, clientId, clientSecret, accessToken, refreshToken, instanceUrl string) (*ForceApi, error)

func (*ForceApi) BulkInsertSObjects

func (forceApi *ForceApi) BulkInsertSObjects(table string, in []SObject) ([]*SObjectResponse, error)

func (*ForceApi) BulkQuerySObjects

func (forceApi *ForceApi) BulkQuerySObjects(table string, query string) ([]*SObjectResponse, error)

func (*ForceApi) BulkUpdateSObjects

func (forceApi *ForceApi) BulkUpdateSObjects(table string, in []SObject) ([]*SObjectResponse, error)

func (*ForceApi) Delete

func (forceApi *ForceApi) Delete(path string, params url.Values) error

Delete issues a DELETE to the specified path with the given payload

func (*ForceApi) DeleteSObject

func (forceApi *ForceApi) DeleteSObject(id string, in SObject) (err error)

func (*ForceApi) DeleteSObjectByExternalId

func (forceApi *ForceApi) DeleteSObjectByExternalId(id string, in SObject) (err error)

func (*ForceApi) DescribeSObject

func (forceApi *ForceApi) DescribeSObject(in SObject) (resp *SObjectDescription, err error)

func (*ForceApi) DescribeSObjects

func (forceAPI *ForceApi) DescribeSObjects() (map[string]*SObjectMetaData, error)

func (*ForceApi) Get

func (forceApi *ForceApi) Get(path string, params url.Values, out interface{}) error

Get issues a GET to the specified path with the given params and put the umarshalled (json) result in the third parameter

func (*ForceApi) GetAccessToken

func (forceApi *ForceApi) GetAccessToken() string

func (*ForceApi) GetApiSObjectDescription

func (forceApi *ForceApi) GetApiSObjectDescription(name string) (*SObjectDescription, error)

func (*ForceApi) GetFields

func (forceApi *ForceApi) GetFields(table string, allowCustomFields bool) (fieldList string, err error)

func (*ForceApi) GetInstanceURL

func (forceApi *ForceApi) GetInstanceURL() string

func (*ForceApi) GetLimits

func (forceApi *ForceApi) GetLimits() (limits *Limits, err error)

func (*ForceApi) GetSObject

func (forceApi *ForceApi) GetSObject(id string, fields []string, out SObject) (err error)

func (*ForceApi) GetSObjectByExternalId

func (forceApi *ForceApi) GetSObjectByExternalId(id string, fields []string, out SObject) (err error)

func (*ForceApi) GetSObjects

func (forceApi *ForceApi) GetSObjects() (map[string]*SObjectMetaData, error)

Get a list of all object types

func (*ForceApi) InsertSObject

func (forceApi *ForceApi) InsertSObject(in SObject) (resp *SObjectResponse, err error)

func (*ForceApi) Patch

func (forceApi *ForceApi) Patch(path string, params url.Values, payload, out interface{}) error

Patch issues a PATCH to the specified path with the given params and payload and put the unmarshalled (json) result in the third parameter

func (*ForceApi) PopulateSessionToken

func (forceApi *ForceApi) PopulateSessionToken() error

func (*ForceApi) Post

func (forceApi *ForceApi) Post(path string, params url.Values, payload, out interface{}) error

Post issues a POST to the specified path with the given params and payload and put the unmarshalled (json) result in the third parameter

func (*ForceApi) Put

func (forceApi *ForceApi) Put(path string, params url.Values, payload, out interface{}) error

Put issues a PUT to the specified path with the given params and payload and put the unmarshalled (json) result in the third parameter

func (*ForceApi) Query

func (forceApi *ForceApi) Query(query string, out interface{}) (err error)

Use the Query resource to execute a SOQL query that returns all the results in a single response, or if needed, returns part of the results and an identifier used to retrieve the remaining results.

func (*ForceApi) QueryAll

func (forceApi *ForceApi) QueryAll(query string, out interface{}) (err error)

Use the QueryAll resource to execute a SOQL query that includes information about records that have been deleted because of a merge or delete. Use QueryAll rather than Query, because the Query resource will automatically filter out items that have been deleted.

func (*ForceApi) QueryNext

func (forceApi *ForceApi) QueryNext(uri string, out interface{}) (err error)

func (*ForceApi) RefreshToken

func (forceApi *ForceApi) RefreshToken() error

func (*ForceApi) TraceOff

func (forceApi *ForceApi) TraceOff()

TraceOff turns off tracing. It is idempotent.

func (*ForceApi) TraceOn

func (forceApi *ForceApi) TraceOn(prefix string, logger ForceApiLogger)

TraceOn turns on logging for this ForceApi. After this is called, all requests, responses, and raw response bodies will be sent to the logger. If prefix is a non-empty string, it will be written to the front of all logged strings, which can aid in filtering log lines.

Use TraceOn if you want to spy on the ForceApi requests and responses.

Note that the base log.Logger type satisfies ForceApiLogger, but adapters can easily be written for other logging packages (e.g., the golang-sanctioned glog framework).

func (*ForceApi) UpdateSObject

func (forceApi *ForceApi) UpdateSObject(id string, in SObject) (err error)

func (*ForceApi) UpsertSObjectByExternalId

func (forceApi *ForceApi) UpsertSObjectByExternalId(id string, in SObject) (resp *SObjectResponse, err error)

type ForceApiInterface

type ForceApiInterface interface {
	BulkInsertSObjects(table string, in []SObject) ([]*SObjectResponse, error)
	BulkUpdateSObjects(table string, in []SObject) ([]*SObjectResponse, error)
	Delete(path string, params url.Values) error
	DeleteSObject(id string, in SObject) (err error)
	DeleteSObjectByExternalId(id string, in SObject) (err error)
	DescribeSObject(in SObject) (resp *SObjectDescription, err error)
	DescribeSObjects() (map[string]*SObjectMetaData, error)
	Get(path string, params url.Values, out interface{}) error
	GetAccessToken() string
	GetInstanceURL() string
	GetLimits() (limits *Limits, err error)
	GetSObject(id string, fields []string, out SObject) (err error)
	GetSObjectByExternalId(id string, fields []string, out SObject) (err error)
	InsertSObject(in SObject) (resp *SObjectResponse, err error)
	Patch(path string, params url.Values, payload, out interface{}) error
	Post(path string, params url.Values, payload, out interface{}) error
	Put(path string, params url.Values, payload, out interface{}) error
	Query(query string, out interface{}) (err error)
	QueryAll(query string, out interface{}) (err error)
	QueryNext(uri string, out interface{}) (err error)
	RefreshToken() error
	TraceOff()
	TraceOn(prefix string, logger ForceApiLogger)
	UpdateSObject(id string, in SObject) (err error)
	UpsertSObjectByExternalId(id string, in SObject) (resp *SObjectResponse, err error)
}

func Create

func Create(version, clientId, clientSecret, userName, password, securityToken,
	environment, prefix string, logger ForceApiLogger) (ForceApiInterface, error)

type ForceApiLogger

type ForceApiLogger interface {
	Printf(format string, v ...interface{})
}

type ForceOauth

type ForceOauth struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	InstanceUrl  string `json:"instance_url"`
	Id           string `json:"id"`
	IssuedAt     string `json:"issued_at"`
	Signature    string `json:"signature"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
	// contains filtered or unexported fields
}

func (*ForceOauth) Authenticate

func (oauth *ForceOauth) Authenticate() error

func (*ForceOauth) AuthenticateCode

func (oauth *ForceOauth) AuthenticateCode(code string, redirectURI string) error

func (*ForceOauth) AuthenticatePayload

func (oauth *ForceOauth) AuthenticatePayload(payload url.Values) ([]byte, error)

func (*ForceOauth) Expired

func (oauth *ForceOauth) Expired(apiErrors ApiErrors) bool

func (*ForceOauth) RefreshAccessToken

func (oauth *ForceOauth) RefreshAccessToken() error

func (*ForceOauth) Validate

func (oauth *ForceOauth) Validate() error

type Limit

type Limit struct {
	Remaining float64
	Max       float64
}

type Limits

type Limits map[string]Limit

type PicklistValue

type PicklistValue struct {
	Value       string `json:"value"`
	DefaulValue bool   `json:"defaultValue"`
	ValidFor    string `json:"validFor"`
	Active      bool   `json:"active"`
	Label       string `json:"label"`
}

type RecordTypeInfo

type RecordTypeInfo struct {
	Name                     string            `json:"name"`
	Available                bool              `json:"available"`
	RecordTypeId             string            `json:"recordTypeId"`
	URLs                     map[string]string `json:"urls"`
	DefaultRecordTypeMapping bool              `json:"defaultRecordTypeMapping"`
}

type RefreshTokenResponse

type RefreshTokenResponse struct {
	ID          string `json:"id"`
	IssuedAt    string `json:"issued_at"`
	Signature   string `json:"signature"`
	AccessToken string `json:"access_token"`
}

type SObject

type SObject interface {
	SetID(string)
	ApiName() string
	ExternalIdApiName() string
}

Interface all standard and custom objects must implement. Needed for uri generation.

type SObjectApiResponse

type SObjectApiResponse struct {
	Encoding     string             `json:"encoding"`
	MaxBatchSize int64              `json:"maxBatchSize"`
	SObjects     []*SObjectMetaData `json:"sobjects"`
}

type SObjectDescription

type SObjectDescription struct {
	Name                string               `json:"name"`
	Fields              []*SObjectField      `json:"fields"`
	KeyPrefix           string               `json:"keyPrefix"`
	Layoutable          bool                 `json:"layoutable"`
	Activateable        bool                 `json:"activateable"`
	LabelPlural         string               `json:"labelPlural"`
	Custom              bool                 `json:"custom"`
	CompactLayoutable   bool                 `json:"compactLayoutable"`
	Label               string               `json:"label"`
	Searchable          bool                 `json:"searchable"`
	URLs                map[string]string    `json:"urls"`
	Queryable           bool                 `json:"queryable"`
	Deletable           bool                 `json:"deletable"`
	Updateable          bool                 `json:"updateable"`
	Createable          bool                 `json:"createable"`
	CustomSetting       bool                 `json:"customSetting"`
	Undeletable         bool                 `json:"undeletable"`
	Mergeable           bool                 `json:"mergeable"`
	Replicateable       bool                 `json:"replicateable"`
	Triggerable         bool                 `json:"triggerable"`
	FeedEnabled         bool                 `json:"feedEnabled"`
	Retrievable         bool                 `json:"retrieveable"`
	SearchLayoutable    bool                 `json:"searchLayoutable"`
	LookupLayoutable    bool                 `json:"lookupLayoutable"`
	Listviewable        bool                 `json:"listviewable"`
	DeprecatedAndHidden bool                 `json:"deprecatedAndHidden"`
	RecordTypeInfos     []*RecordTypeInfo    `json:"recordTypeInfos"`
	ChildRelationsips   []*ChildRelationship `json:"childRelationships"`

	AllFields string `json:"-"` // Not from force.com API. Used to generate SELECT * queries.
}

type SObjectError

type SObjectError struct {
	Message              string      `json:"message"`
	Fields               []string    `json:"fields"`
	StatusCode           string      `json:"statusCode"`
	ExtendedErrorDetails interface{} `json:"extendedErrorDetails"`
}

type SObjectField

type SObjectField struct {
	Length                   float64          `json:"length"`
	Name                     string           `json:"name"`
	Type                     string           `json:"type"`
	DefaultValue             interface{}      `json:"defaultValue"`
	RestrictedPicklist       bool             `json:"restrictedPicklist"`
	NameField                bool             `json:"nameField"`
	ByteLength               float64          `json:"byteLength"`
	Precision                float64          `json:"precision"`
	Filterable               bool             `json:"filterable"`
	Sortable                 bool             `json:"sortable"`
	Unique                   bool             `json:"unique"`
	CaseSensitive            bool             `json:"caseSensitive"`
	Calculated               bool             `json:"calculated"`
	Scale                    float64          `json:"scale"`
	Label                    string           `json:"label"`
	NamePointing             bool             `json:"namePointing"`
	Custom                   bool             `json:"custom"`
	HtmlFormatted            bool             `json:"htmlFormatted"`
	DependentPicklist        bool             `json:"dependentPicklist"`
	Permissionable           bool             `json:"permissionable"`
	ReferenceTo              []string         `json:"referenceTo"`
	RelationshipOrder        float64          `json:"relationshipOrder"`
	SoapType                 string           `json:"soapType"`
	CalculatedValueFormula   string           `json:"calculatedValueFormula"`
	DefaultValueFormula      string           `json:"defaultValueFormula"`
	DefaultedOnCreate        bool             `json:"defaultedOnCreate"`
	Digits                   float64          `json:"digits"`
	Groupable                bool             `json:"groupable"`
	Nillable                 bool             `json:"nillable"`
	InlineHelpText           string           `json:"inlineHelpText"`
	WriteRequiresMasterRead  bool             `json:"writeRequiresMasterRead"`
	PicklistValues           []*PicklistValue `json:"picklistValues"`
	Updateable               bool             `json:"updateable"`
	Createable               bool             `json:"createable"`
	DeprecatedAndHidden      bool             `json:"deprecatedAndHidden"`
	DisplayLocationInDecimal bool             `json:"displayLocationInDecimal"`
	CascadeDelete            bool             `json:"cascasdeDelete"`
	RestrictedDelete         bool             `json:"restrictedDelete"`
	ControllerName           string           `json:"controllerName"`
	ExternalId               bool             `json:"externalId"`
	IdLookup                 bool             `json:"idLookup"`
	AutoNumber               bool             `json:"autoNumber"`
	RelationshipName         string           `json:"relationshipName"`
}

type SObjectMetaData

type SObjectMetaData struct {
	Name                string            `json:"name"`
	Label               string            `json:"label"`
	KeyPrefix           string            `json:"keyPrefix"`
	LabelPlural         string            `json:"labelPlural"`
	Custom              bool              `json:"custom"`
	Layoutable          bool              `json:"layoutable"`
	Activateable        bool              `json:"activateable"`
	URLs                map[string]string `json:"urls"`
	Searchable          bool              `json:"searchable"`
	Updateable          bool              `json:"updateable"`
	Createable          bool              `json:"createable"`
	DeprecatedAndHidden bool              `json:"deprecatedAndHidden"`
	CustomSetting       bool              `json:"customSetting"`
	Deletable           bool              `json:"deletable"`
	FeedEnabled         bool              `json:"feedEnabled"`
	Mergeable           bool              `json:"mergeable"`
	Queryable           bool              `json:"queryable"`
	Replicateable       bool              `json:"replicateable"`
	Retrieveable        bool              `json:"retrieveable"`
	Undeletable         bool              `json:"undeletable"`
	Triggerable         bool              `json:"triggerable"`
}

type SObjectResponse

type SObjectResponse struct {
	Id      string         `json:"id,omitempty"`
	Errors  []SObjectError `json:"errors,omitempty"` //TODO: Not sure if ApiErrors is the right object
	Success bool           `json:"success,omitempty"`
}

Response recieved from force.com API after insert of an sobject.

type Version

type Version struct {
	Label   string `json:"label"`
	URL     string `json:"url"`
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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