Documentation
¶
Overview ¶
Package salesforce provides a comprehensive, production-grade Go SDK for Salesforce.
Index ¶
- Constants
- Variables
- type APIError
- type APIErrors
- type APIVersionInfo
- type ApexService
- type AuthError
- type Authenticator
- type BulkService
- type CompositeRequest
- type CompositeResponse
- type CompositeSubrequest
- type CompositeSubresponse
- type Config
- type CreateJobRequest
- type ErrorCode
- type ExecuteAnonymousResult
- type FailedRecord
- type GlobalDescribeResult
- type JobInfo
- type LimitInfo
- type Limits
- type Logger
- type Option
- func WithAPIVersion(version string) Option
- func WithBaseURL(baseURL string) Option
- func WithCredentials(clientID, clientSecret string) Option
- func WithDebug(debug bool) Option
- func WithHTTPClient(client *http.Client) Option
- func WithInstanceURL(instanceURL string) Option
- func WithLogger(logger types.Logger) Option
- func WithOAuthRefresh(clientID, clientSecret, refreshToken string) Option
- func WithPasswordAuth(username, password, securityToken string) Option
- func WithRetry(maxRetries int, waitMin, waitMax time.Duration) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTokenURL(tokenURL string) Option
- type QueryBuilder
- type QueryResult
- type QueryService
- type RateLimitError
- type SObject
- type SObjectMetadata
- type SObjectService
- type SalesforceClient
- func (c *SalesforceClient) APIVersion() string
- func (c *SalesforceClient) Apex() ApexService
- func (c *SalesforceClient) ApexREST(ctx context.Context, method, path string, body io.Reader) ([]byte, error)
- func (c *SalesforceClient) Bulk() BulkService
- func (c *SalesforceClient) Close() error
- func (c *SalesforceClient) Connect(ctx context.Context) error
- func (c *SalesforceClient) ExecuteComposite(ctx context.Context, req CompositeRequest) (*CompositeResponse, error)
- func (c *SalesforceClient) GetLimits(ctx context.Context) (*Limits, error)
- func (c *SalesforceClient) GetToken() *types.Token
- func (c *SalesforceClient) GetVersions(ctx context.Context) ([]APIVersionInfo, error)
- func (c *SalesforceClient) InstanceURL() string
- func (c *SalesforceClient) Query() QueryService
- func (c *SalesforceClient) RefreshToken(ctx context.Context) error
- func (c *SalesforceClient) SObjects() SObjectService
- func (c *SalesforceClient) SetAccessToken(accessToken, instanceURL string)
- func (c *SalesforceClient) Tooling() ToolingService
- type Token
- type ToolingService
- type ValidationError
Constants ¶
const ( DefaultAPIVersion = types.DefaultAPIVersion DefaultTimeout = types.DefaultTimeout DefaultMaxRetries = types.DefaultMaxRetries )
Re-export constants
const ( ErrorCodeInvalidSession = types.ErrorCodeInvalidSession ErrorCodeSessionExpired = types.ErrorCodeSessionExpired ErrorCodeInvalidField = types.ErrorCodeInvalidField ErrorCodeMalformedQuery = types.ErrorCodeMalformedQuery ErrorCodeInvalidType = types.ErrorCodeInvalidType ErrorCodeEntityDeleted = types.ErrorCodeEntityDeleted ErrorCodeDuplicateValue = types.ErrorCodeDuplicateValue ErrorCodeRequiredFieldMissing = types.ErrorCodeRequiredFieldMissing ErrorCodeInvalidCrossRef = types.ErrorCodeInvalidCrossRef ErrorCodeInsufficientAccess = types.ErrorCodeInsufficientAccess ErrorCodeRequestLimit = types.ErrorCodeRequestLimit ErrorCodeStorageLimit = types.ErrorCodeStorageLimit )
Re-export error codes
Variables ¶
var ( ParseAPIError = types.ParseAPIError IsNotFoundError = types.IsNotFoundError IsAuthError = types.IsAuthError IsRateLimitError = types.IsRateLimitError )
Re-export helper functions
var NewQueryBuilder = services.NewQueryBuilder
NewQueryBuilder creates a new query builder.
var NewSObject = services.NewSObject
NewSObject creates a new SObject.
Functions ¶
This section is empty.
Types ¶
type APIVersionInfo ¶
type APIVersionInfo struct {
Label string `json:"label"`
URL string `json:"url"`
Version string `json:"version"`
}
APIVersionInfo represents a Salesforce API version.
type ApexService ¶
type ApexService interface {
Execute(ctx context.Context, method, path string, body interface{}) ([]byte, error)
}
ApexService defines operations for executing Apex REST endpoints.
type Authenticator ¶
type Authenticator interface {
Authenticate(ctx context.Context) (*Token, error)
Refresh(ctx context.Context) (*Token, error)
IsTokenValid() bool
}
Authenticator defines the interface for authentication strategies.
type BulkService ¶
type BulkService interface {
CreateJob(ctx context.Context, req CreateJobRequest) (*JobInfo, error)
UploadData(ctx context.Context, jobID string, data io.Reader) error
CloseJob(ctx context.Context, jobID string) (*JobInfo, error)
GetJobStatus(ctx context.Context, jobID string) (*JobInfo, error)
GetSuccessfulRecords(ctx context.Context, jobID string) ([]map[string]interface{}, error)
GetFailedRecords(ctx context.Context, jobID string) ([]FailedRecord, error)
AbortJob(ctx context.Context, jobID string) (*JobInfo, error)
DeleteJob(ctx context.Context, jobID string) error
}
BulkService defines operations for Bulk API 2.0.
type CompositeRequest ¶
type CompositeRequest struct {
AllOrNone bool `json:"allOrNone"`
CompositeRequest []CompositeSubrequest `json:"compositeRequest"`
}
CompositeRequest represents a composite API request.
type CompositeResponse ¶
type CompositeResponse struct {
CompositeResponse []CompositeSubresponse `json:"compositeResponse"`
}
CompositeResponse represents the response from a composite API request.
type CompositeSubrequest ¶
type CompositeSubrequest struct {
Method string `json:"method"`
URL string `json:"url"`
ReferenceId string `json:"referenceId"`
Body map[string]interface{} `json:"body,omitempty"`
}
CompositeSubrequest represents a single subrequest.
type CompositeSubresponse ¶
type CompositeSubresponse struct {
Body interface{} `json:"body"`
HTTPStatusCode int `json:"httpStatusCode"`
ReferenceId string `json:"referenceId"`
}
CompositeSubresponse represents a single subresponse.
type Config ¶
type Config struct {
// Authentication
Username string
Password string
SecurityToken string
ClientID string
ClientSecret string
RefreshToken string
TokenURL string
// Connection
BaseURL string
InstanceURL string
APIVersion string
Timeout time.Duration
// Retry settings
MaxRetries int
RetryWaitMin time.Duration
RetryWaitMax time.Duration
// Advanced
Logger types.Logger
HTTPClient *http.Client
Debug bool
}
Config holds the configuration for the Salesforce client.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with default values.
type ExecuteAnonymousResult ¶
type ExecuteAnonymousResult = services.ExecuteAnonymousResult
Re-export service types
type GlobalDescribeResult ¶
type GlobalDescribeResult = services.GlobalDescribeResult
Re-export service types
type LimitInfo ¶
LimitInfo contains limit details.
func (LimitInfo) PercentUsed ¶
PercentUsed returns the percentage of limit used.
type Limits ¶
type Limits struct {
DailyApiRequests LimitInfo `json:"DailyApiRequests"`
}
Limits represents Salesforce API limits.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the client.
func WithAPIVersion ¶
WithAPIVersion sets the Salesforce API version.
func WithBaseURL ¶
WithBaseURL sets the base URL for authentication.
func WithCredentials ¶
WithCredentials sets the OAuth client credentials.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client.
func WithInstanceURL ¶
WithInstanceURL sets the Salesforce instance URL.
func WithOAuthRefresh ¶
WithOAuthRefresh configures OAuth 2.0 refresh token authentication.
func WithPasswordAuth ¶
WithPasswordAuth configures username/password authentication.
func WithTimeout ¶
WithTimeout sets the HTTP timeout.
func WithTokenURL ¶
WithTokenURL sets the OAuth token endpoint URL.
type QueryService ¶
type QueryService interface {
Execute(ctx context.Context, query string) (*QueryResult, error)
ExecuteAll(ctx context.Context, query string) (*QueryResult, error)
QueryMore(ctx context.Context, nextRecordsURL string) (*QueryResult, error)
NewBuilder(objectType string) *QueryBuilder
}
QueryService defines operations for SOQL queries.
type SObjectService ¶
type SObjectService interface {
Create(ctx context.Context, objectType string, data map[string]interface{}) (*SObject, error)
Get(ctx context.Context, objectType, id string, fields ...string) (*SObject, error)
Update(ctx context.Context, objectType, id string, data map[string]interface{}) error
Upsert(ctx context.Context, objectType, externalIDField, externalID string, data map[string]interface{}) (*SObject, error)
Delete(ctx context.Context, objectType, id string) error
Describe(ctx context.Context, objectType string) (*SObjectMetadata, error)
DescribeGlobal(ctx context.Context) (*GlobalDescribeResult, error)
}
SObjectService defines operations on Salesforce SObjects.
type SalesforceClient ¶
type SalesforceClient struct {
// contains filtered or unexported fields
}
SalesforceClient is the main client for interacting with Salesforce.
func NewClient ¶
func NewClient(opts ...Option) (*SalesforceClient, error)
NewClient creates a new Salesforce client with the given options.
func (*SalesforceClient) APIVersion ¶
func (c *SalesforceClient) APIVersion() string
APIVersion returns the API version being used.
func (*SalesforceClient) Apex ¶
func (c *SalesforceClient) Apex() ApexService
Apex returns the Apex REST service.
func (*SalesforceClient) ApexREST ¶
func (c *SalesforceClient) ApexREST(ctx context.Context, method, path string, body io.Reader) ([]byte, error)
ApexREST makes a request to a custom Apex REST endpoint.
func (*SalesforceClient) Bulk ¶
func (c *SalesforceClient) Bulk() BulkService
Bulk returns the Bulk API service.
func (*SalesforceClient) Close ¶
func (c *SalesforceClient) Close() error
Close cleans up any resources held by the client.
func (*SalesforceClient) Connect ¶
func (c *SalesforceClient) Connect(ctx context.Context) error
Connect authenticates and establishes connection to Salesforce.
func (*SalesforceClient) ExecuteComposite ¶
func (c *SalesforceClient) ExecuteComposite(ctx context.Context, req CompositeRequest) (*CompositeResponse, error)
ExecuteComposite executes a composite request.
func (*SalesforceClient) GetLimits ¶
func (c *SalesforceClient) GetLimits(ctx context.Context) (*Limits, error)
GetLimits retrieves the current API limits for the org.
func (*SalesforceClient) GetToken ¶
func (c *SalesforceClient) GetToken() *types.Token
GetToken returns the current token (implements TokenProvider).
func (*SalesforceClient) GetVersions ¶
func (c *SalesforceClient) GetVersions(ctx context.Context) ([]APIVersionInfo, error)
GetVersions retrieves available API versions.
func (*SalesforceClient) InstanceURL ¶
func (c *SalesforceClient) InstanceURL() string
InstanceURL returns the Salesforce instance URL.
func (*SalesforceClient) Query ¶
func (c *SalesforceClient) Query() QueryService
Query returns the Query service.
func (*SalesforceClient) RefreshToken ¶
func (c *SalesforceClient) RefreshToken(ctx context.Context) error
RefreshToken refreshes the access token (implements TokenProvider).
func (*SalesforceClient) SObjects ¶
func (c *SalesforceClient) SObjects() SObjectService
SObjects returns the SObject service.
func (*SalesforceClient) SetAccessToken ¶
func (c *SalesforceClient) SetAccessToken(accessToken, instanceURL string)
SetAccessToken sets the access token directly.
func (*SalesforceClient) Tooling ¶
func (c *SalesforceClient) Tooling() ToolingService
Tooling returns the Tooling API service.
type ToolingService ¶
type ToolingService interface {
Query(ctx context.Context, query string) (*QueryResult, error)
ExecuteAnonymous(ctx context.Context, apexCode string) (*ExecuteAnonymousResult, error)
Describe(ctx context.Context, objectType string) (*SObjectMetadata, error)
}
ToolingService defines operations for the Tooling API.