sobjects

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: 6 Imported by: 0

Documentation

Overview

Package sobjects provides SObject CRUD operations for Salesforce.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

type Attributes struct {
	Type string `json:"type"`
	URL  string `json:"url,omitempty"`
}

Attributes contains SObject metadata.

type ChildRelation

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

ChildRelation describes a child relationship.

type CreateResult

type CreateResult struct {
	ID      string  `json:"id"`
	Success bool    `json:"success"`
	Errors  []Error `json:"errors,omitempty"`
}

CreateResult contains the result of a create operation.

type DeletedRecord

type DeletedRecord struct {
	ID          string `json:"id"`
	DeletedDate string `json:"deletedDate"`
}

DeletedRecord represents a deleted record.

type DeletedRecords

type DeletedRecords struct {
	DeletedRecords        []DeletedRecord `json:"deletedRecords"`
	EarliestDateAvailable string          `json:"earliestDateAvailable"`
	LatestDateCovered     string          `json:"latestDateCovered"`
}

DeletedRecords contains deleted record information.

type Error

type Error struct {
	StatusCode string   `json:"statusCode"`
	Message    string   `json:"message"`
	Fields     []string `json:"fields,omitempty"`
}

Error represents an operation error.

type FieldMetadata

type FieldMetadata struct {
	Name             string          `json:"name"`
	Label            string          `json:"label"`
	Type             string          `json:"type"`
	Length           int             `json:"length"`
	Precision        int             `json:"precision"`
	Scale            int             `json:"scale"`
	Createable       bool            `json:"createable"`
	Updateable       bool            `json:"updateable"`
	Nillable         bool            `json:"nillable"`
	Unique           bool            `json:"unique"`
	Custom           bool            `json:"custom"`
	ExternalId       bool            `json:"externalId"`
	AutoNumber       bool            `json:"autoNumber"`
	Calculated       bool            `json:"calculated"`
	NameField        bool            `json:"nameField"`
	IdLookup         bool            `json:"idLookup"`
	DefaultValue     interface{}     `json:"defaultValue"`
	ReferenceTo      []string        `json:"referenceTo,omitempty"`
	RelationshipName string          `json:"relationshipName,omitempty"`
	PicklistValues   []PicklistValue `json:"picklistValues,omitempty"`
}

FieldMetadata describes a field.

type GlobalDescribe

type GlobalDescribe struct {
	Encoding     string     `json:"encoding"`
	MaxBatchSize int        `json:"maxBatchSize"`
	SObjects     []Metadata `json:"sobjects"`
}

GlobalDescribe contains all accessible SObjects.

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 Metadata

type Metadata struct {
	Name               string           `json:"name"`
	Label              string           `json:"label"`
	LabelPlural        string           `json:"labelPlural"`
	KeyPrefix          string           `json:"keyPrefix"`
	Createable         bool             `json:"createable"`
	Updateable         bool             `json:"updateable"`
	Deletable          bool             `json:"deletable"`
	Queryable          bool             `json:"queryable"`
	Searchable         bool             `json:"searchable"`
	Retrieveable       bool             `json:"retrieveable"`
	Undeletable        bool             `json:"undeletable"`
	Mergeable          bool             `json:"mergeable"`
	Replicateable      bool             `json:"replicateable"`
	Triggerable        bool             `json:"triggerable"`
	FeedEnabled        bool             `json:"feedEnabled"`
	HasSubtypes        bool             `json:"hasSubtypes"`
	IsSubtype          bool             `json:"isSubtype"`
	Custom             bool             `json:"custom"`
	CustomSetting      bool             `json:"customSetting"`
	Fields             []FieldMetadata  `json:"fields,omitempty"`
	ChildRelationships []ChildRelation  `json:"childRelationships,omitempty"`
	RecordTypeInfos    []RecordTypeInfo `json:"recordTypeInfos,omitempty"`
}

Metadata contains SObject describe information.

type PicklistValue

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

PicklistValue represents a picklist option.

type RecordTypeInfo

type RecordTypeInfo struct {
	Name                     string `json:"name"`
	RecordTypeId             string `json:"recordTypeId"`
	Available                bool   `json:"available"`
	DefaultRecordTypeMapping bool   `json:"defaultRecordTypeMapping"`
	Master                   bool   `json:"master"`
}

RecordTypeInfo describes a record type.

type SObject

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

SObject represents a Salesforce SObject record.

func FromMap

func FromMap(data map[string]interface{}) *SObject

FromMap creates an SObject from a map.

func New

func New(objectType string) *SObject

New creates a new SObject of the specified type.

func (*SObject) Attributes

func (s *SObject) Attributes() *Attributes

Attributes returns the SObject attributes.

func (*SObject) BoolField

func (s *SObject) BoolField(key string) bool

BoolField returns a field as bool.

func (*SObject) FloatField

func (s *SObject) FloatField(key string) float64

FloatField returns a field as float64.

func (*SObject) Get

func (s *SObject) Get(key string) interface{}

Get returns a field value.

func (*SObject) ID

func (s *SObject) ID() string

ID returns the record ID.

func (*SObject) IntField

func (s *SObject) IntField(key string) int

IntField returns a field as int.

func (*SObject) MarshalJSON

func (s *SObject) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SObject) Related

func (s *SObject) Related(key string) *SObject

Related returns a related SObject.

func (*SObject) RelatedList

func (s *SObject) RelatedList(key string) []*SObject

RelatedList returns a list of related SObjects.

func (*SObject) Set

func (s *SObject) Set(key string, value interface{}) *SObject

Set sets a field value.

func (*SObject) StringField

func (s *SObject) StringField(key string) string

StringField returns a field as string.

func (*SObject) TimeField

func (s *SObject) TimeField(key string) time.Time

TimeField returns a field as time.Time.

func (*SObject) ToCreatePayload

func (s *SObject) ToCreatePayload() map[string]interface{}

ToCreatePayload returns fields suitable for create/update.

func (*SObject) ToMap

func (s *SObject) ToMap() map[string]interface{}

ToMap returns the SObject as a map.

func (*SObject) Type

func (s *SObject) Type() string

Type returns the SObject type.

func (*SObject) UnmarshalJSON

func (s *SObject) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Service

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

Service provides SObject CRUD operations.

func NewService

func NewService(client HTTPClient, apiVersion string) *Service

NewService creates a new SObject service.

func (*Service) Create

func (s *Service) Create(ctx context.Context, objectType string, data map[string]interface{}) (*CreateResult, error)

Create creates a new SObject record.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, objectType, id string) error

Delete deletes an SObject by ID.

func (*Service) Describe

func (s *Service) Describe(ctx context.Context, objectType string) (*Metadata, error)

Describe returns metadata for an SObject type.

func (*Service) DescribeGlobal

func (s *Service) DescribeGlobal(ctx context.Context) (*GlobalDescribe, error)

DescribeGlobal returns all accessible SObject types.

func (*Service) Get

func (s *Service) Get(ctx context.Context, objectType, id string, fields ...string) (*SObject, error)

Get retrieves an SObject by ID.

func (*Service) GetByExternalID

func (s *Service) GetByExternalID(ctx context.Context, objectType, extIDField, extID string) (*SObject, error)

GetByExternalID retrieves an SObject by external ID.

func (*Service) GetDeleted

func (s *Service) GetDeleted(ctx context.Context, objectType string, start, end time.Time) (*DeletedRecords, error)

GetDeleted retrieves deleted records for an SObject type.

func (*Service) GetUpdated

func (s *Service) GetUpdated(ctx context.Context, objectType string, start, end time.Time) (*UpdatedRecords, error)

GetUpdated retrieves updated record IDs for an SObject type.

func (*Service) Update

func (s *Service) Update(ctx context.Context, objectType, id string, data map[string]interface{}) error

Update updates an existing SObject.

func (*Service) Upsert

func (s *Service) Upsert(ctx context.Context, objectType, extIDField, extID string, data map[string]interface{}) (*CreateResult, error)

Upsert upserts an SObject by external ID.

type UpdatedRecords

type UpdatedRecords struct {
	IDs               []string `json:"ids"`
	LatestDateCovered string   `json:"latestDateCovered"`
}

UpdatedRecords contains updated record IDs.

Jump to

Keyboard shortcuts

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