bulk

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bulk provides Bulk API 2.0 operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnDelimiter

type ColumnDelimiter string

ColumnDelimiter represents CSV column delimiters.

const (
	DelimiterComma     ColumnDelimiter = "COMMA"
	DelimiterTab       ColumnDelimiter = "TAB"
	DelimiterSemicolon ColumnDelimiter = "SEMICOLON"
	DelimiterPipe      ColumnDelimiter = "PIPE"
	DelimiterBackquote ColumnDelimiter = "BACKQUOTE"
	DelimiterCaret     ColumnDelimiter = "CARET"
)

type ContentType

type ContentType string

ContentType represents data content types.

const (
	ContentTypeCSV  ContentType = "CSV"
	ContentTypeJSON ContentType = "JSON"
)

type CreateJobRequest

type CreateJobRequest struct {
	Object              string          `json:"object"`
	Operation           Operation       `json:"operation"`
	ExternalIdFieldName string          `json:"externalIdFieldName,omitempty"`
	ContentType         ContentType     `json:"contentType,omitempty"`
	LineEnding          LineEnding      `json:"lineEnding,omitempty"`
	ColumnDelimiter     ColumnDelimiter `json:"columnDelimiter,omitempty"`
}

CreateJobRequest contains job creation parameters.

type FailedRecord

type FailedRecord struct {
	ID    string                 `json:"sf__Id"`
	Error string                 `json:"sf__Error"`
	Data  map[string]interface{} `json:"-"`
}

FailedRecord represents a failed record.

type HTTPClient

type HTTPClient interface {
	Get(ctx context.Context, path string) ([]byte, error)
	Post(ctx context.Context, path string, body interface{}) ([]byte, error)
	Patch(ctx context.Context, path string, body interface{}) ([]byte, error)
	Put(ctx context.Context, path string, body interface{}) ([]byte, error)
	Delete(ctx context.Context, path string) ([]byte, error)
}

HTTPClient interface for dependency injection.

type JobInfo

type JobInfo struct {
	ID                      string      `json:"id"`
	Object                  string      `json:"object"`
	Operation               Operation   `json:"operation"`
	State                   State       `json:"state"`
	ContentType             ContentType `json:"contentType"`
	ColumnDelimiter         string      `json:"columnDelimiter"`
	LineEnding              LineEnding  `json:"lineEnding"`
	ExternalIdFieldName     string      `json:"externalIdFieldName,omitempty"`
	CreatedById             string      `json:"createdById"`
	CreatedDate             string      `json:"createdDate"`
	SystemModstamp          string      `json:"systemModstamp"`
	ConcurrencyMode         string      `json:"concurrencyMode"`
	ContentURL              string      `json:"contentUrl,omitempty"`
	NumberRecordsProcessed  int         `json:"numberRecordsProcessed"`
	NumberRecordsFailed     int         `json:"numberRecordsFailed"`
	Retries                 int         `json:"retries"`
	TotalProcessingTime     int         `json:"totalProcessingTime"`
	ApiActiveProcessingTime int         `json:"apiActiveProcessingTime"`
	ApexProcessingTime      int         `json:"apexProcessingTime"`
	ErrorMessage            string      `json:"errorMessage,omitempty"`
}

JobInfo contains bulk job information.

func (*JobInfo) IsComplete

func (j *JobInfo) IsComplete() bool

IsComplete returns true if the job has finished.

func (*JobInfo) IsSuccess

func (j *JobInfo) IsSuccess() bool

IsSuccess returns true if the job completed successfully.

type JobListResult

type JobListResult struct {
	Done           bool      `json:"done"`
	Records        []JobInfo `json:"records"`
	NextRecordsURL string    `json:"nextRecordsUrl,omitempty"`
}

JobListResult contains a list of jobs.

type LineEnding

type LineEnding string

LineEnding represents line ending types.

const (
	LineEndingLF   LineEnding = "LF"
	LineEndingCRLF LineEnding = "CRLF"
)

type Operation

type Operation string

Operation represents bulk job operation types.

const (
	OperationInsert     Operation = "insert"
	OperationUpdate     Operation = "update"
	OperationUpsert     Operation = "upsert"
	OperationDelete     Operation = "delete"
	OperationHardDelete Operation = "hardDelete"
)

type QueryJobInfo

type QueryJobInfo struct {
	ID                     string      `json:"id"`
	Operation              Operation   `json:"operation"`
	Object                 string      `json:"object"`
	State                  State       `json:"state"`
	ContentType            ContentType `json:"contentType"`
	CreatedById            string      `json:"createdById"`
	CreatedDate            string      `json:"createdDate"`
	SystemModstamp         string      `json:"systemModstamp"`
	NumberRecordsProcessed int         `json:"numberRecordsProcessed"`
}

QueryJobInfo contains query job information.

type QueryJobRequest

type QueryJobRequest struct {
	Query       string      `json:"query"`
	Operation   Operation   `json:"operation,omitempty"`
	ContentType ContentType `json:"contentType,omitempty"`
}

QueryJobRequest contains query job creation parameters.

type Service

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

Service provides Bulk API 2.0 operations.

func NewService

func NewService(client HTTPClient, apiVersion string) *Service

NewService creates a new Bulk service.

func (*Service) AbortJob

func (s *Service) AbortJob(ctx context.Context, jobID string) (*JobInfo, error)

AbortJob aborts an ingest job.

func (*Service) AbortQueryJob

func (s *Service) AbortQueryJob(ctx context.Context, jobID string) (*QueryJobInfo, error)

AbortQueryJob aborts a query job.

func (*Service) CloseJob

func (s *Service) CloseJob(ctx context.Context, jobID string) (*JobInfo, error)

CloseJob closes an ingest job to begin processing.

func (*Service) CreateJob

func (s *Service) CreateJob(ctx context.Context, req CreateJobRequest) (*JobInfo, error)

CreateJob creates a new ingest job.

func (*Service) CreateQueryJob

func (s *Service) CreateQueryJob(ctx context.Context, req QueryJobRequest) (*QueryJobInfo, error)

CreateQueryJob creates a bulk query job.

func (*Service) DeleteJob

func (s *Service) DeleteJob(ctx context.Context, jobID string) error

DeleteJob deletes an ingest job.

func (*Service) DeleteQueryJob

func (s *Service) DeleteQueryJob(ctx context.Context, jobID string) error

DeleteQueryJob deletes a query job.

func (*Service) GetFailedRecords

func (s *Service) GetFailedRecords(ctx context.Context, jobID string) ([]FailedRecord, error)

GetFailedRecords retrieves failed records.

func (*Service) GetJob

func (s *Service) GetJob(ctx context.Context, jobID string) (*JobInfo, error)

GetJob retrieves job information.

func (*Service) GetQueryJob

func (s *Service) GetQueryJob(ctx context.Context, jobID string) (*QueryJobInfo, error)

GetQueryJob retrieves query job information.

func (*Service) GetQueryResults

func (s *Service) GetQueryResults(ctx context.Context, jobID string, maxRecords int, locator string) ([]map[string]interface{}, string, error)

GetQueryResults retrieves query job results.

func (*Service) GetSuccessfulRecords

func (s *Service) GetSuccessfulRecords(ctx context.Context, jobID string) ([]SuccessRecord, error)

GetSuccessfulRecords retrieves successfully processed records.

func (*Service) GetUnprocessedRecords

func (s *Service) GetUnprocessedRecords(ctx context.Context, jobID string) ([]map[string]interface{}, error)

GetUnprocessedRecords retrieves unprocessed records.

func (*Service) ListJobs

func (s *Service) ListJobs(ctx context.Context, concurrencyMode string, isPkChunkingEnabled bool) (*JobListResult, error)

ListJobs lists all ingest jobs.

func (*Service) UploadCSV

func (s *Service) UploadCSV(ctx context.Context, jobID string, records []map[string]interface{}, columns []string) error

UploadCSV uploads CSV data to an ingest job.

func (*Service) UploadData

func (s *Service) UploadData(ctx context.Context, jobID string, data io.Reader) error

UploadData uploads data to an ingest job.

func (*Service) WaitForCompletion

func (s *Service) WaitForCompletion(ctx context.Context, jobID string, pollInterval time.Duration) (*JobInfo, error)

WaitForCompletion waits for a job to complete.

type State

type State string

State represents bulk job states.

const (
	StateOpen           State = "Open"
	StateUploadComplete State = "UploadComplete"
	StateInProgress     State = "InProgress"
	StateJobComplete    State = "JobComplete"
	StateFailed         State = "Failed"
	StateAborted        State = "Aborted"
)

type SuccessRecord

type SuccessRecord struct {
	ID      string                 `json:"sf__Id"`
	Created bool                   `json:"sf__Created"`
	Data    map[string]interface{} `json:"-"`
}

SuccessRecord represents a successful record.

Jump to

Keyboard shortcuts

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