sfdc

package module
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: BSD-3-Clause-Clear Imports: 17 Imported by: 0

README

stellar

go-sfdc

Tests Go Reference GitHub Tag

Testing Environment Variables

The following environment variables must be set (and valid) for tests to run.

Key Description
SFDC_CLIENT_ID Connected App OAuth2 Client ID (Consumer Key)
SFDC_CLIENT_SECRET Connected App OAuth2 Client Secret (Consumer Secret)
SFDC_ENCRYPTION_PASSPHRASE AES-256 key for encrypting cache values
SFDC_AUTH_URL Salesforce Authentication URL
SFDC_TEST_DATA JSON string of test data, see below

Test Data

The following values are used in unit tests to fetch and validate data through the go-sfdc client methods.

Key Description
accountId ID of pre-existing Account object
userId ID of pre-existing User account
groupId ID of pre-existing group (Queue)
accountName Name of Account used in the accountId field
contactId ID of pre-existing contact that is associated with the Account used in the accountId field
accountCustomFieldKey Field name of a custom field on the Account object
caseCustomFieldKey Field name of a custom field on the Case object
userEmail Email address of the User used in the userId field
serviceContractId ID of pre-existing Service Contract object
Example
{
    "accountId": "001A000001abcde123",
    "userId": "005A000001xyz7890",
    "groupId": "00G1A00000abcdef12",
    "accountName": "Acme Corp, Inc.",
    "contactId": "003A000001pqrst456",
    "accountCustomFieldKey": "go_sfdc_Test_Field__c",
    "caseCustomFieldKey": "go_sfdc_Test_Field__c",
    "userEmail": "person@example.com",
    "serviceContractId": "0SCA00000lmnop789"
}

Documentation

Overview

Methods that handle methods through the Bulk API.

Methods that consume object _and_ SOQL methods, or that handle data processing.

Methods that handle objects.

Methods that query SOQL.

Index

Examples

Constants

View Source
const API_VERSION string = "v58.0"
View Source
const DefaultRetryDuration time.Duration = time.Second * 10
View Source
const PATH_ACCOUNT string = "/services/data/%s/sobjects/Account"
View Source
const PATH_BULK_INGEST string = "/services/data/%s/jobs/ingest"
View Source
const PATH_BULK_INGEST_COMPLETE string = "/services/data/%s/jobs/ingest/%s"
View Source
const PATH_CASE string = "/services/data/%s/sobjects/Case"
View Source
const PATH_CONTACT string = "/services/data/%s/sobjects/Contact"
View Source
const PATH_FEED_ITEM string = "/services/data/%s/sobjects/FeedItem"
View Source
const PATH_GROUP string = "/services/data/%s/sobjects/Group"
View Source
const PATH_PRICEBOOK_ENTRY string = "/services/data/%s/sobjects/PricebookEntry"
View Source
const PATH_SERVICE_CONTRACT string = "/services/data/%s/sobjects/ServiceContract"
View Source
const PATH_SOQL string = "/services/data/%s/query"
View Source
const PATH_USER string = "/services/data/%s/sobjects/User"

Variables

View Source
var BulkJobCompleteData = BulkJobComplete{State: "UploadComplete"}

Functions

func MarshalCSV added in v0.4.2

func MarshalCSV(base any, customFields ...map[string]any) (string, error)

func MarshalCSVSlice added in v0.4.5

func MarshalCSVSlice(base any) (string, error)

func SOQL

func SOQL() *soql

Create a (limited, for now) SOQL queries using a Go API.

Types

type Account added in v0.2.0

type Account struct {
	BaseObject
	AccountSource           string       `json:"AccountSource,omitempty"`
	BillingAddress          *Address     `json:"BillingAddress,omitempty"`
	BillingCity             string       `json:"BillingCity,omitempty"`
	BillingCountry          string       `json:"BillingCountry,omitempty"`
	BillingGeocodeAccuracy  string       `json:"BillingGeocodeAccuracy,omitempty"`
	BillingLatitude         int          `json:"BillingLatitude,omitempty"`
	BillingLongitude        int          `json:"BillingLongitude,omitempty"`
	BillingPostalCode       string       `json:"BillingPostalCode,omitempty"`
	BillingState            string       `json:"BillingState,omitempty"`
	BillingStreet           string       `json:"BillingStreet,omitempty"`
	ConnectionReceivedID    string       `json:"ConnectionReceivedId,omitempty"`
	Description             string       `json:"Description,omitempty"`
	Industry                string       `json:"Industry,omitempty"`
	IsCustomerPortal        bool         `json:"IsCustomerPortal"`
	IsDeleted               bool         `json:"IsDeleted,omitempty"`
	Jigsaw                  string       `json:"Jigsaw,omitempty"`
	JigsawCompanyID         string       `json:"JigsawCompanyId,omitempty"`
	LastReferencedDate      string       `json:"LastReferencedDate,omitempty"`
	LastViewedDate          string       `json:"LastViewedDate,omitempty"`
	MasterRecordID          string       `json:"MasterRecordId,omitempty"`
	Name                    string       `json:"Name"`
	NumberOfEmployees       int          `json:"NumberOfEmployees,omitempty"`
	ParentID                string       `json:"ParentId,omitempty"`
	Phone                   string       `json:"Phone,omitempty"`
	PhotoUrl                string       `json:"PhotoUrl,omitempty"`
	ShippingAddress         *Address     `json:"ShippingAddress,omitempty"`
	ShippingCity            string       `json:"ShippingCity,omitempty"`
	ShippingCountry         string       `json:"ShippingCountry,omitempty"`
	ShippingGeocodeAccuracy string       `json:"ShippingGeocodeAccuracy,omitempty"`
	ShippingLatitude        int          `json:"ShippingLatitude,omitempty"`
	ShippingLongitude       int          `json:"ShippingLongitude,omitempty"`
	ShippingPostalCode      string       `json:"ShippingPostalCode,omitempty"`
	ShippingState           string       `json:"ShippingState,omitempty"`
	ShippingStreet          string       `json:"ShippingStreet,omitempty"`
	SicDesc                 string       `json:"SicDesc,omitempty"`
	Type                    string       `json:"Type,omitempty"`
	Website                 string       `json:"Website,omitempty"`
	CustomFields            CustomFields `json:"-"`
}

type Address added in v0.2.0

type Address struct {
	City            string `json:"city,omitempty"`
	Country         string `json:"country,omitempty"`
	GeocodeAccuracy string `json:"geocodeAccuracy,omitempty"`
	Latitude        int    `json:"latitude,omitempty"`
	Longitude       int    `json:"longitude,omitempty"`
	State           string `json:"state,omitempty"`
	Street          string `json:"street,omitempty"`
}

type Attributes added in v0.2.0

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

type Auth added in v0.2.0

type Auth struct {
	InstanceURL *url.URL
	// contains filtered or unexported fields
}

func NewAuth added in v0.2.0

func NewAuth(
	clientID, clientSecret, authURL string,
	encryption *string,
	getAccessTokenCallback CachedTokenCallback,
	setAccessTokenCallback SetTokenCallback,
) (auth *Auth, err error)

func (*Auth) CacheNewToken added in v0.2.0

func (auth *Auth) CacheNewToken(token *Token) (err error)

func (*Auth) GetAccessToken added in v0.2.0

func (auth *Auth) GetAccessToken() (token string, err error)

func (*Auth) GetNewToken added in v0.2.0

func (auth *Auth) GetNewToken() (*Token, error)

func (*Auth) IntrospectToken added in v0.4.0

func (auth *Auth) IntrospectToken(token string) (*TokenIntrospection, error)

func (*Auth) SetAccessToken added in v0.2.0

func (auth *Auth) SetAccessToken(token *Token) (err error)

type AuthErrorResponse added in v0.2.0

type AuthErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

func (*AuthErrorResponse) GetError added in v0.2.0

func (a *AuthErrorResponse) GetError() error

func (*AuthErrorResponse) GetErrorString added in v0.2.0

func (a *AuthErrorResponse) GetErrorString() string

type BaseObject added in v0.2.0

type BaseObject struct {
	Attributes       *Attributes `json:"attributes,omitempty"`
	CreatedByID      string      `json:"CreatedById,omitempty"`
	CreatedDate      string      `json:"CreatedDate,omitempty"`
	ID               string      `json:"Id,omitempty"`
	LastModifiedByID string      `json:"LastModifiedById,omitempty"`
	LastModifiedDate string      `json:"LastModifiedDate,omitempty"`
	OwnerID          string      `json:"OwnerId,omitempty"`
	SystemModStamp   string      `json:"SystemModstamp,omitempty"`
}

type BulkClient added in v0.4.2

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

func NewBulkClient added in v0.4.2

func NewBulkClient(client *Client) *BulkClient

func (*BulkClient) Insert added in v0.4.2

func (bc *BulkClient) Insert(bulkJob *BulkJob, data any, cf ...map[string]any) (*BulkJobCompleteResponse, error)

func (*BulkClient) InsertMultiple added in v0.4.5

func (bc *BulkClient) InsertMultiple(bulkJob *BulkJob, data any) (*BulkJobCompleteResponse, error)

func (*BulkClient) InsertRaw added in v0.4.3

func (bc *BulkClient) InsertRaw(bulkJob *BulkJob, data string) (*BulkJobCompleteResponse, error)

func (*BulkClient) JobIsAborted added in v0.4.4

func (bc *BulkClient) JobIsAborted(id string) (bool, error)

func (*BulkClient) JobIsComplete added in v0.4.4

func (bc *BulkClient) JobIsComplete(id string) (bool, error)

func (*BulkClient) JobIsFailed added in v0.4.4

func (bc *BulkClient) JobIsFailed(id string) (bool, error)

func (*BulkClient) JobIsInProgress added in v0.4.4

func (bc *BulkClient) JobIsInProgress(id string) (bool, error)

func (*BulkClient) JobIsOpen added in v0.4.4

func (bc *BulkClient) JobIsOpen(id string) (bool, error)

func (*BulkClient) JobStatus added in v0.4.4

func (bc *BulkClient) JobStatus(id string) (*BulkJobStatus, error)

func (*BulkClient) NewInsertJob added in v0.4.4

func (bc *BulkClient) NewInsertJob(object string) *BulkJob

func (*BulkClient) NewUpsertJob added in v0.4.4

func (bc *BulkClient) NewUpsertJob(object string, extIDField string) *BulkJob

func (*BulkClient) Upsert added in v0.4.4

func (bc *BulkClient) Upsert(bulkJob *BulkJob, data any, cf ...map[string]any) (*BulkJobCompleteResponse, error)

func (*BulkClient) UpsertMultiple added in v0.4.5

func (bc *BulkClient) UpsertMultiple(bulkJob *BulkJob, data any) (*BulkJobCompleteResponse, error)

func (*BulkClient) UpsertRaw added in v0.4.4

func (bc *BulkClient) UpsertRaw(bulkJob *BulkJob, data string) (*BulkJobCompleteResponse, error)

type BulkJob added in v0.4.2

type BulkJob struct {
	Object              string `json:"object"`
	ContentType         string `json:"contentType"`
	Operation           string `json:"operation"`
	LineEnding          string `json:"lineEnding"`
	ExternalIDFieldName string `json:"externalIdFieldName,omitempty"`
}

type BulkJobComplete added in v0.4.2

type BulkJobComplete struct {
	State string `json:"state"`
}

type BulkJobCompleteResponse added in v0.4.2

type BulkJobCompleteResponse struct {
	ID              string  `json:"id"`
	Operation       string  `json:"operation"`
	Object          string  `json:"object"`
	CreatedByID     string  `json:"createdById"`
	CreatedDate     string  `json:"createdDate"`
	SystemModstamp  string  `json:"systemModstamp"`
	State           string  `json:"state"`
	ConcurrencyMode string  `json:"concurrencyMode"`
	ContentType     string  `json:"contentType"`
	APIVersion      float64 `json:"apiVersion"`
}

type BulkJobResponse added in v0.4.2

type BulkJobResponse struct {
	ID              string  `json:"id"`
	Operation       string  `json:"operation"`
	Object          string  `json:"object"`
	CreatedByID     string  `json:"createdById"`
	CreatedDate     string  `json:"createdDate"`
	SystemModstamp  string  `json:"systemModstamp"`
	State           string  `json:"state"`
	ConcurrencyMode string  `json:"concurrencyMode"`
	ContentType     string  `json:"contentType"`
	APIVersion      float64 `json:"apiVersion"`
	ContentURL      string  `json:"contentUrl"`
	LineEnding      string  `json:"lineEnding"`
	ColumnDelimiter string  `json:"columnDelimiter"`
}

type BulkJobStatus added in v0.4.2

type BulkJobStatus struct {
	ID                      string  `json:"id"`
	Operation               string  `json:"operation"`
	Object                  string  `json:"object"`
	CreatedByID             string  `json:"createdById"`
	CreatedDate             string  `json:"createdDate"`
	SystemModstamp          string  `json:"systemModstamp"`
	State                   string  `json:"state"`
	ConcurrencyMode         string  `json:"concurrencyMode"`
	ContentType             string  `json:"contentType"`
	APIVersion              float64 `json:"apiVersion"`
	JobType                 string  `json:"jobType"`
	LineEnding              string  `json:"lineEnding"`
	ColumnDelimiter         string  `json:"columnDelimiter"`
	NumberRecordsProcessed  int     `json:"numberRecordsProcessed"`
	NumberRecordsFailed     int     `json:"numberRecordsFailed"`
	Retries                 int     `json:"retries"`
	TotalProcessingTime     int     `json:"totalProcessingTime"`
	APIActiveProcessingTime int     `json:"apiActiveProcessingTime"`
	ApexProcessingTime      int     `json:"apexProcessingTime"`
}

type CachedTokenCallback added in v0.2.0

type CachedTokenCallback func() (string, error)

type Case added in v0.2.0

type Case struct {
	BaseObject
	AccountId          string       `json:"AccountId,omitempty"`
	CaseNumber         string       `json:"CaseNumber,omitempty"`
	ClosedDate         string       `json:"ClosedDate,omitempty"`
	Comments           string       `json:"Comments,omitempty"`
	ContactEmail       string       `json:"ContactEmail,omitempty"`
	ContactFax         string       `json:"ContactFax,omitempty"`
	ContactID          string       `json:"ContactId,omitempty"`
	ContactMobile      string       `json:"ContactMobile,omitempty"`
	ContactPhone       string       `json:"ContactPhone,omitempty"`
	Description        string       `json:"Description,omitempty"`
	EntitlementID      string       `json:"EntitlementId,omitempty"`
	IsClosed           bool         `json:"IsClosed,omitempty"`
	IsDeleted          bool         `json:"IsDeleted,omitempty"`
	IsEscalated        bool         `json:"IsEscalated,omitempty"`
	IsStopped          bool         `json:"IsStopped,omitempty"`
	Language           string       `json:"Language,omitempty"`
	LastReferencedDate string       `json:"LastReferencedDate,omitempty"`
	LastViewedDate     string       `json:"LastViewedDate,omitempty"`
	MasterRecordID     string       `json:"MasterRecordId,omitempty"`
	MilestoneStatus    string       `json:"MilestoneStatus,omitempty"`
	Origin             string       `json:"Origin,omitempty"`
	OwnerID            string       `json:"OwnerId,omitempty"`
	ParentID           string       `json:"ParentId,omitempty"`
	Reason             string       `json:"Reason,omitempty"`
	Status             string       `json:"Status,omitempty"`
	StopStartDate      string       `json:"StopStartDate,omitempty"`
	Subject            string       `json:"Subject,omitempty"`
	SuppliedCompany    string       `json:"SuppliedCompany,omitempty"`
	SuppliedEmail      string       `json:"SuppliedEmail,omitempty"`
	SuppliedName       string       `json:"SuppliedName,omitempty"`
	SuppliedPhone      string       `json:"SuppliedPhone,omitempty"`
	Type               string       `json:"Type,omitempty"`
	CustomFields       CustomFields `json:"-"`
}

type CaseCreate added in v0.2.0

type CaseCreate struct {
	AccountID    string       `json:"AccountId,omitempty"`
	Comments     string       `json:"Comments,omitempty"`
	ContactID    string       `json:"ContactId,omitempty"`
	Description  string       `json:"Description,omitempty"`
	Origin       string       `json:"Origin,omitempty"`
	Status       string       `json:"Status,omitempty"`
	Subject      string       `json:"Subject,omitempty"`
	CustomFields CustomFields `json:"-"`
}

type CaseUpdate added in v0.2.0

type CaseUpdate struct {
	// Options
	SkipAutoAssign bool `json:"-"`
	// Fields
	Comments        string `json:"Comments,omitempty"`
	ContactEmail    string `json:"ContactEmail,omitempty"`
	ContactFax      string `json:"ContactFax,omitempty"`
	ContactID       string `json:"ContactId,omitempty"`
	ContactMobile   string `json:"ContactMobile,omitempty"`
	ContactPhone    string `json:"ContactPhone,omitempty"`
	Description     string `json:"Description,omitempty"`
	EntitlementID   string `json:"EntitlementId,omitempty"`
	IsEscalated     bool   `json:"IsEscalated,omitempty"`
	IsStopped       bool   `json:"IsStopped,omitempty"`
	Language        string `json:"Language,omitempty"`
	MasterRecordID  string `json:"MasterRecordId,omitempty"`
	MilestoneStatus string `json:"MilestoneStatus,omitempty"`
	Origin          string `json:"Origin,omitempty"`
	OwnerID         string `json:"OwnerId,omitempty"`
	ParentId        string `json:"ParentId,omitempty"`
	Reason          string `json:"Reason,omitempty"`
	Status          string `json:"Status,omitempty"`
	StopStartDate   string `json:"StopStartDate,omitempty"`
	Subject         string `json:"Subject,omitempty"`
	SuppliedCompany string `json:"SuppliedCompany,omitempty"`
	SuppliedEmail   string `json:"SuppliedEmail,omitempty"`
	SuppliedName    string `json:"SuppliedName,omitempty"`
	SuppliedPhone   string `json:"SuppliedPhone,omitempty"`
	Type            string `json:"Type,omitempty"`
}

type Client

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

Salesforce Client

func New added in v0.2.0

func New(
	clientID, clientSecret, authURL string,
	encryption *string,
	getToken CachedTokenCallback,
	setToken SetTokenCallback,
) (*Client, error)

Create a go-sfdc client and performs initial authentication.

Example

In this example, the cache2go caching backend is used, but any caching backend can be used.

cache := cache2go.Cache("go-sfdc")
cache.Flush()

// Define a callback function to retrieve the Salesforce OAuth2 access token from the cache.
getAccessToken := func() (string, error) {
	res, err := cache.Value("access-token")
	if err != nil {
		return "", nil
	}
	token := res.Data().(string)
	return token, nil
}

// Define a callback function to add the Salesforce OAuth2 access token from the cache.
setAccessToken := func(token string, expiresIn time.Duration) error {
	cache.Add("access-token", expiresIn, token)
	return nil
}

// Salesforce Connected App OAuth2 Client ID.
clientID := "abcdef1234567890"

// Salesforce Connected App OAuth2 Client Secret.
clientSecret := "0987654321fedcba"

// If set, the encryption passphrase is used to encrypt all values written to the cache
// using AES-256-GCM encryption.
var encryptionPassphrase *string
passphrase := "xY2jK9a8s6d5fE7H"
encryptionPassphrase = &passphrase

// If you do not wish to encrypt cached values, pass nil.
encryptionPassphrase = nil

// Salesforce authentication URL.
// See: https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_jwt_flow.htm
authURL := "https://login.salesforce.com"

client, err := sfdc.New(
	clientID,
	clientSecret,
	authURL,
	encryptionPassphrase,
	getAccessToken,
	setAccessToken,
)
if err != nil {
	// handle error
}
client.Account("001G00000789QPONML")
Output:

func (*Client) Account

func (client *Client) Account(id string) (account *Account, err error)

Retrieve an Account.

Example
account, err := client.Account("006G00000678LKJIHE")
if err != nil {
	// handle error
}
fmt.Println(account.ID)
// Example Output: 006G00000678LKJIHE
Output:

func (*Client) AccountIDFromName

func (client *Client) AccountIDFromName(name string) (id string, err error)

Find an account's ID based on the account's name.

Example
id, err := client.AccountIDFromName("Acme Corp")
if err != nil {
	// handle error
}
fmt.Println(id)
// Example Output: 001G00000456MNOPQR
Output:

func (*Client) Bulk added in v0.4.2

func (client *Client) Bulk() *BulkClient

Bulk performs a bulk operation using BulkClient.

func (*Client) Case

func (client *Client) Case(id string) (_case *Case, err error)

Retrieve a Case.

Example
_case, err := client.Case("001G00000987KJIHGF")
if err != nil {
	// handle error
}
fmt.Println(_case.ID)
// Example Output: 001G00000987KJIHGF
Output:

func (*Client) CaseByNumber added in v0.0.3

func (client *Client) CaseByNumber(caseNumber string) (result *Case, err error)

Retrieve a case by its case number.

func (*Client) CloseCase added in v0.0.3

func (client *Client) CloseCase(caseID string) (err error)

Close an open case.

func (*Client) Contact

func (client *Client) Contact(id string) (contact *Contact, err error)

Retrieve a Contact.

Example
contact, err := client.Contact("003G00000123ZYXWVU")
if err != nil {
	// handle error
}
fmt.Println(contact.ID)
// Example Output: 003G00000123ZYXWVU
Output:

func (*Client) CreateCase added in v0.0.2

func (client *Client) CreateCase(data *CaseCreate, customFields ...map[string]any) (result *RecordCreatedResponse, err error)

Create a new case.

func (*Client) CreateFeedItem added in v0.2.9

func (client *Client) CreateFeedItem(data *FeedItemOptions) (*RecordCreatedResponse, error)

func (*Client) Customers

func (client *Client) Customers() (accounts []Customer, err error)

Retrieve a summary of all accounts where the 'Type' field is 'Customer'.

Example
customers, err := client.Customers()
if err != nil {
	// handle error
}
for _, customer := range customers {
	fmt.Printf("Id=%s, Name=%s, Type=%s", customer.ID, customer.Name, customer.Type)
	// Example Output: Id=00QG00000567DCBAZY, Name=Acme Corp, Type=Customer
	// ...
}
Output:

func (*Client) DeleteObject added in v0.4.1

func (client *Client) DeleteObject(path string) error

DeleteObject deletes an existing object.

func (*Client) Do added in v0.4.0

func (client *Client) Do(doer func(u string) (*resty.Response, error), url string) (*resty.Response, error)

Do executes a given resty request method such as Get/Post. If a timeout/backoff is specified, the request will be executed and retried within that timeout period.

func (*Client) FeedItem added in v0.0.10

func (client *Client) FeedItem(id string) (result *FeedItem, err error)

func (*Client) GetObject added in v0.4.1

func (client *Client) GetObject(path string) (*ObjectResponse, error)

GetObject retrieves an object and provides an interface to access its data.

func (*Client) Group

func (client *Client) Group(id string) (group *Group, err error)

Retrieve a Group.

Example
group, err := client.Account("00QG00000890ZYXWVU")
if err != nil {
	// handle error
}
fmt.Println(group.ID)
// Example Output: 00QG00000890ZYXWVU
Output:

func (*Client) GroupName

func (client *Client) GroupName(id string) (name string, err error)

Retrieve the name of a group based on the group's ID.

Example
name, err := client.GroupName("006G00000345LKJIHG")
if err != nil {
	// handle error
}
fmt.Println(name)
// Example Output: Help Desk
Output:

func (*Client) OpenCases

func (client *Client) OpenCases() (cases []OpenCase, err error)

Retrieve a summary of all open cases.

Example
openCases, err := client.OpenCases()
if err != nil {
	// handle error
}
for _, openCase := range openCases {
	fmt.Printf("Id=%s, Subject=%s, OwnerId=%s", openCase.ID, openCase.Subject, openCase.OwnerID)
}
// Example Output:
// Id=003G000002z8VBQIA2, Subject=Case Subject, OwnerId=00QG00000234ZYXWVU
Output:

func (*Client) PatchObject added in v0.4.1

func (client *Client) PatchObject(path string, data map[string]any) error

PatchObject updates an existing object.

func (*Client) PostObject added in v0.4.1

func (client *Client) PostObject(path string, data map[string]any) (*RecordCreatedResponse, error)

PostObject creates a new object.

func (*Client) PostToCase added in v0.0.3

func (client *Client) PostToCase(caseID string, content string, feedOptions *FeedItemOptions) (result *RecordCreatedResponse, err error)

Post a comment to a case.

func (*Client) SendCaseUpdate added in v0.4.4

func (client *Client) SendCaseUpdate(id string, data *Case, cf ...map[string]any) (*BulkJobCompleteResponse, error)

func (*Client) SendCloseCase added in v0.4.4

func (client *Client) SendCloseCase(id string) error

func (*Client) SendFeedItem added in v0.4.4

func (client *Client) SendFeedItem(item *FeedItemOptions) (*BulkJobCompleteResponse, error)

func (*Client) ServiceContract added in v0.2.7

func (client *Client) ServiceContract(id string) (contract *ServiceContract, err error)

Retrieve a Service Contract.

func (*Client) UpdateAccount added in v0.0.2

func (client *Client) UpdateAccount(id string, data any, customFields ...map[string]any) (err error)

Update an account's fields.

func (*Client) UpdateCase added in v0.0.2

func (client *Client) UpdateCase(id string, data *CaseUpdate, customFields ...map[string]any) (err error)

Update a case's fields.

func (*Client) User

func (client *Client) User(id string) (user *User, err error)

Retrieve a User.

Example
user, err := client.Account("003G00000789VUTSRQ")
if err != nil {
	// handle error
}
fmt.Println(user.ID)
// Example Output: 003G00000789VUTSRQ
Output:

func (*Client) UserByEmail added in v0.2.2

func (client *Client) UserByEmail(email string) (user *User, err error)

Retrieve a user by its email address.

func (*Client) UserName

func (client *Client) UserName(id string) (name string, err error)

Retrieve the name of a user based on that user's ID.

Example
name, err := client.UserName("001G00000123ABCDEF")
if err != nil {
	// handle error
}
fmt.Println(name)
// Example Output: John Doe
Output:

func (*Client) WithRetry added in v0.4.0

func (client *Client) WithRetry(timeout time.Duration) *Client

WithRetry specifies a time period in which to retry all requests if a errors are returned.

type Contact added in v0.2.0

type Contact struct {
	BaseObject
	AccountID              string       `json:"AccountId,omitempty"`
	IsDeleted              bool         `json:"IsDeleted,omitempty"`
	MasterRecordID         string       `json:"MasterRecordId,omitempty"`
	LastName               string       `json:"LastName,omitempty"`
	FirstName              string       `json:"FirstName,omitempty"`
	MiddleName             string       `json:"MiddleName,omitempty"`
	Suffix                 string       `json:"Suffix,omitempty"`
	Name                   string       `json:"Name,omitempty"`
	Salutation             string       `json:"Salutation,omitempty"`
	MailingStreet          string       `json:"MailingStreet,omitempty"`
	MailingCity            string       `json:"MailingCity,omitempty"`
	MailingState           string       `json:"MailingState,omitempty"`
	MailingPostalCode      string       `json:"MailingPostalCode,omitempty"`
	MailingCountry         string       `json:"MailingCountry,omitempty"`
	MailingLatitude        int          `json:"MailingLatitude,omitempty"`
	MailingLongitude       int          `json:"MailingLongitude,omitempty"`
	MailingGeocodeAccuracy string       `json:"MailingGeocodeAccuracy,omitempty"`
	MailingAddress         *Address     `json:"MailingAddress,omitempty"`
	Phone                  string       `json:"Phone,omitempty"`
	Fax                    string       `json:"Fax,omitempty"`
	MobilePhone            string       `json:"MobilePhone,omitempty"`
	ReportsToId            string       `json:"ReportsToId,omitempty"`
	Email                  string       `json:"Email,omitempty"`
	Title                  string       `json:"Title,omitempty"`
	Department             string       `json:"Department,omitempty"`
	LastActivityDate       string       `json:"LastActivityDate,omitempty"`
	CustomFields           CustomFields `json:"-"`
}

type CustomFields added in v0.2.0

type CustomFields map[string]any

type Customer added in v0.2.0

type Customer struct {
	ID   string `json:"Id"`
	Name string `json:"Name"`
	Type string `json:"Type"`
}

type Date added in v0.2.7

type Date struct {
	time.Time
}

func (*Date) UnmarshalJSON added in v0.2.7

func (d *Date) UnmarshalJSON(b []byte) (err error)

type FeedItem added in v0.2.0

type FeedItem struct {
	Attributes         *Attributes `json:"attributes,omitempty"`
	ID                 string      `json:"Id,omitempty"`
	ParentID           string      `json:"ParentId,omitempty"`
	Type               string      `json:"Type,omitempty"`
	CreatedByID        string      `json:"CreatedById,omitempty"`
	CreatedDate        string      `json:"CreatedDate,omitempty"`
	IsDeleted          bool        `json:"IsDeleted,omitempty"`
	LastModifiedDate   string      `json:"LastModifiedDate,omitempty"`
	SystemModstamp     string      `json:"SystemModstamp,omitempty"`
	Revision           int         `json:"Revision,omitempty"`
	LastEditByID       string      `json:"LastEditById,omitempty"`
	LastEditDate       string      `json:"LastEditDate,omitempty"`
	ConnectionID       string      `json:"ConnectionId,omitempty"`
	CommentCount       int         `json:"CommentCount,omitempty"`
	LikeCount          int         `json:"LikeCount,omitempty"`
	Title              string      `json:"Title,omitempty"`
	Body               string      `json:"Body,omitempty"`
	LinkURL            string      `json:"LinkUrl,omitempty"`
	IsRichText         bool        `json:"IsRichText,omitempty"`
	RelatedRecordID    string      `json:"RelatedRecordId,omitempty"`
	InsertedByID       string      `json:"InsertedById,omitempty"`
	NetworkScope       string      `json:"NetworkScope,omitempty"`
	Visibility         string      `json:"Visibility,omitempty"`
	BestCommentID      string      `json:"BestCommentId,omitempty"`
	HasContent         bool        `json:"HasContent,omitempty"`
	HasLink            bool        `json:"HasLink,omitempty"`
	HasFeedEntity      bool        `json:"HasFeedEntity,omitempty"`
	HasVerifiedComment bool        `json:"HasVerifiedComment,omitempty"`
	IsClosed           bool        `json:"IsClosed,omitempty"`
	Status             string      `json:"Status,omitempty"`
}

type FeedItemOptions added in v0.2.0

type FeedItemOptions struct {
	// ID of the user that posts the feed item.
	CreatedByID string `json:"CreatedById,omitempty"`
	// ID of whatever this is attached to (most likely, the case ID).
	ParentID string `json:"ParentId,omitempty"`
	// Title of the feed item.
	Title string `json:"Title,omitempty"`
	// Body - required if Type is TextPost.
	Body string `json:"Body,omitempty"`
	// Temporarily only supporting "TextPost".
	Type string `json:"Type,omitempty"`
	/* If true, these HTML tags are supported:
	<p/>
	<a/>
	<b/>
	<code/>
	<i/>
	<u/>
	<s/>
	<ul/>
	<ol/>
	<li/>
	<img/>
	*/
	IsRichText bool `json:"IsRichText,omitempty"`
	/*
	   Specifies whether this feed item is available to all users or internal users only.
	   "AllUsers": The feed item is available to all users who have permission to see the feed item.
	   "InternalUsers": The feed item is available to internal users only.

	   For record posts, Visibility is set to InternalUsers for all internal users by default.
	   External users can set Visibility only to AllUsers.
	   Visibility can be updated on record posts.
	   The Update property is supported only for feed items posted on records.
	*/
	Visibility string `json:"Visibility,omitempty"`
}

type GenericResponse added in v0.2.0

type GenericResponse struct {
	Message string         `json:"message"`
	Data    map[string]any `json:"data,omitempty"`
}

type Group added in v0.2.0

type Group struct {
	BaseObject
	Name                   string       `json:"Name"`
	Developer_Name         string       `json:"Developer_Name,omitempty"`
	RelatedID              string       `json:"RelatedId,omitempty"`
	QueueRoutingConfigID   string       `json:"QueueRoutingConfigId,omitempty"`
	DoesSendEmailToMembers bool         `json:"DoesSendEmailToMembers,omitempty"`
	DoesIncludeBosses      bool         `json:"DoesIncludeBosses,omitempty"`
	Email                  string       `json:"Email,omitempty"`
	Type                   string       `json:"Type,omitempty"`
	CustomFields           CustomFields `json:"-"`
}

type JWTClaim added in v0.2.0

type JWTClaim struct {
	Iss string `json:"iss"`
	Aud string `json:"aud"`
	Sub string `json:"sub"`
	Exp string `json:"exp"`
}

type JWTHeader added in v0.2.0

type JWTHeader struct {
	Alg string `json:"alg"`
}

type ObjectID added in v0.2.0

type ObjectID struct {
	ID string `json:"Id"`
}

type ObjectResponse added in v0.4.1

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

func NewObjectResponse added in v0.4.1

func NewObjectResponse(data []byte) (*ObjectResponse, error)

func (*ObjectResponse) GetBool added in v0.4.1

func (obj *ObjectResponse) GetBool(key string) bool

func (*ObjectResponse) GetFloat32 added in v0.4.1

func (obj *ObjectResponse) GetFloat32(key string) float32

func (*ObjectResponse) GetFloat64 added in v0.4.1

func (obj *ObjectResponse) GetFloat64(key string) float64

func (*ObjectResponse) GetInt added in v0.4.1

func (obj *ObjectResponse) GetInt(key string) int

func (*ObjectResponse) GetMap added in v0.4.1

func (obj *ObjectResponse) GetMap(key string) map[string]any

func (*ObjectResponse) GetSlice added in v0.4.1

func (obj *ObjectResponse) GetSlice(key string) []any

func (*ObjectResponse) GetString added in v0.4.1

func (obj *ObjectResponse) GetString(key string) string

type ObjectSummary added in v0.2.0

type ObjectSummary struct {
	ID   string `json:"Id"`
	Name string `json:"Name"`
}

type OpenCase added in v0.2.0

type OpenCase struct {
	ID      string `json:"Id"`
	Subject string `json:"Subject"`
	OwnerID string `json:"OwnerId"`
}

type RecordCreatedResponse added in v0.2.0

type RecordCreatedResponse struct {
	Errors  []string `json:"errors"`
	ID      string   `json:"id"`
	Success bool     `json:"success"`
}

type RecordResponse added in v0.2.0

type RecordResponse[R any] struct {
	Done      bool `json:"done"`
	TotalSize int  `json:"totalSize"`
	Records   []R  `json:"records"`
}

type SOQLClient added in v0.0.5

type SOQLClient[T any] struct {
	Client
}

func NewSOQL added in v0.2.0

func NewSOQL[T any](client *Client) (sc *SOQLClient[T])

func (*SOQLClient[T]) Query added in v0.0.5

func (soqlClient *SOQLClient[T]) Query(soqlQuery *soql) (results RecordResponse[T], err error)

Query the Salesforce SOQL API with the created SOQL query.

type SOQLOperator added in v0.2.1

type SOQLOperator string
const CONTAINS SOQLOperator = "CONTAINS"
const ENDS_WITH SOQLOperator = "ENDS WITH"
const EQUALS SOQLOperator = "="
const EXCLUDES SOQLOperator = "EXCLUDES"
const GEQUAL SOQLOperator = ">="
const GREATER_THAN SOQLOperator = ">"
const IN SOQLOperator = "IN"
const INCLUDES SOQLOperator = "INCLUDES"
const LEQUAL SOQLOperator = "<="
const LESS_THAN SOQLOperator = "<"
const LIKE SOQLOperator = "LIKE"
const NOT_EQUALS SOQLOperator = "!="
const NOT_IN SOQLOperator = "NOT IN"
const STARTS_WITH SOQLOperator = "STARTS WITH"

type SalesforceError added in v0.2.0

type SalesforceError struct {
	Fields    []string `json:"fields"`
	ErrorCode string   `json:"errorCode"`
	Message   string   `json:"message"`
}

type SalesforceErrorResponse added in v0.2.0

type SalesforceErrorResponse []*SalesforceError

func (*SalesforceErrorResponse) GetError added in v0.2.0

func (er *SalesforceErrorResponse) GetError() error

func (*SalesforceErrorResponse) GetErrorString added in v0.2.0

func (er *SalesforceErrorResponse) GetErrorString() string

type ServiceContract added in v0.2.7

type ServiceContract struct {
	BaseObject
	AccountID               string   `json:"AccountId,omitempty"`
	ActivationDate          string   `json:"ActivationDate,omitempty"`
	ApprovalStatus          string   `json:"ApprovalStatus,omitempty"`
	BillingAddress          *Address `json:"BillingAddress,omitempty"`
	BillingCity             string   `json:"BillingCity,omitempty"`
	BillingCountry          string   `json:"BillingCountry,omitempty"`
	BillingGeocodeAccuracy  string   `json:"BillingGeocodeAccuracy,omitempty"`
	BillingLatitude         int      `json:"BillingLatitude,omitempty"`
	BillingLongitude        int      `json:"BillingLongitude,omitempty"`
	BillingPostalCode       string   `json:"BillingPostalCode,omitempty"`
	BillingState            string   `json:"BillingState,omitempty"`
	BillingStreet           string   `json:"BillingStreet,omitempty"`
	ContactID               string   `json:"ContactId,omitempty"`
	ContractNumber          string   `json:"ContractNumber,omitempty"`
	Description             string   `json:"Description,omitempty"`
	Discount                float64  `json:"Discount,omitempty"`
	EndDate                 string   `json:"EndDate,omitempty"`
	GrandTotal              float64  `json:"GrandTotal,omitempty"`
	IsDeleted               bool     `json:"IsDeleted,omitempty"`
	LastReferencedDate      string   `json:"LastReferencedDate,omitempty"`
	LastViewedDate          string   `json:"LastViewedDate,omitempty"`
	LineItemCount           int      `json:"LineItemCount,omitempty"`
	Name                    string   `json:"Name,omitempty"`
	ParentServiceContractID string   `json:"ParentServiceContractId,omitempty"`
	Pricebook2ID            string   `json:"Pricebook2Id,omitempty"`
	RecordTypeID            string   `json:"RecordTypeId,omitempty"`
	RootServiceContractID   string   `json:"RootServiceContractId,omitempty"`
	ShippingAddress         *Address `json:"ShippingAddress,omitempty"`
	ShippingCity            string   `json:"ShippingCity,omitempty"`
	ShippingCountry         string   `json:"ShippingCountry,omitempty"`
	ShippingGeocodeAccuracy string   `json:"ShippingGeocodeAccuracy,omitempty"`
	ShippingLatitude        int      `json:"ShippingLatitude,omitempty"`
	ShippingLongitude       int      `json:"ShippingLongitude,omitempty"`
	ShippingPostalCode      string   `json:"ShippingPostalCode,omitempty"`
	ShippingState           string   `json:"ShippingState,omitempty"`
	ShippingStreet          string   `json:"ShippingStreet,omitempty"`
	ShippingHandling        float64  `json:"ShippingHandling,omitempty"`
	SpecialTerms            string   `json:"SpecialTerms,omitempty"`
	StartDate               string   `json:"StartDate,omitempty"`
	Status                  string   `json:"Status,omitempty"`
	Subtotal                float64  `json:"Subtotal,omitempty"`
	SystemModstamp          string   `json:"SystemModstamp,omitempty"`
	Tax                     float64  `json:"Tax,omitempty"`
	Term                    int      `json:"Term,omitempty"`
	TotalPrice              float64  `json:"TotalPrice,omitempty"`
}

type SetTokenCallback added in v0.2.0

type SetTokenCallback func(token string, expiresIn time.Duration) error

type Time added in v0.2.7

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON added in v0.2.7

func (t *Time) UnmarshalJSON(b []byte) (err error)

type Token added in v0.2.0

type Token struct {
	ID          string `json:"id"`
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`
	AccessToken string `json:"access_token"`
	InstanceURL string `json:"instance_url"`
	IssuedAt    string `json:"issued_at"`
	Signature   string `json:"signature"`
	// contains filtered or unexported fields
}

func (*Token) IsExpired added in v0.4.0

func (token *Token) IsExpired() bool

func (*Token) JSON added in v0.2.0

func (token *Token) JSON() string

func (*Token) SetExpiry added in v0.4.0

func (token *Token) SetExpiry(exp int) *Token

type TokenIntrospection added in v0.4.0

type TokenIntrospection struct {
	Active    bool   `json:"active"`
	Scope     string `json:"scope"`
	ClientID  string `json:"client_id"`
	Username  string `json:"username"`
	Sub       string `json:"sub"`
	TokenType string `json:"token_type"`
	Exp       int    `json:"exp"`
	Iat       int    `json:"iat"`
	Nbf       int    `json:"nbf"`
}

type User added in v0.2.0

type User struct {
	BaseObject
	Username          string       `json:"Username"`
	LastName          string       `json:"LastName,omitempty"`
	FirstName         string       `json:"FirstName,omitempty"`
	MiddleName        string       `json:"MiddleName,omitempty"`
	Suffix            string       `json:"Suffix,omitempty"`
	Name              string       `json:"Name,omitempty"`
	CompanyName       string       `json:"CompanyName,omitempty"`
	Division          string       `json:"Division,omitempty"`
	Department        string       `json:"Department,omitempty"`
	Title             string       `json:"Title,omitempty"`
	Street            string       `json:"Street,omitempty"`
	City              string       `json:"City,omitempty"`
	State             string       `json:"State,omitempty"`
	PostalCode        string       `json:"PostalCode,omitempty"`
	Country           string       `json:"Country,omitempty"`
	Latitude          int          `json:"Latitude,omitempty"`
	Longitude         int          `json:"Longitude,omitempty"`
	GeocodeAccuracy   string       `json:"GeocodeAccuracy,omitempty"`
	Address           *Address     `json:"Address,omitempty"`
	Email             string       `json:"Email,omitempty"`
	Phone             string       `json:"Phone,omitempty"`
	Alias             string       `json:"Alias,omitempty"`
	CommunityNickname string       `json:"CommunityNickname,omitempty"`
	IsActive          bool         `json:"IsActive,omitempty"`
	TimeZoneSidKey    string       `json:"TimeZoneSidKey,omitempty"`
	UserRoleID        string       `json:"UserRoleId,omitempty"`
	ManagerID         string       `json:"ManagerId,omitempty"`
	UserType          string       `json:"UserType,omitempty"`
	ProfileID         string       `json:"ProfileId,omitempty"`
	ContactID         string       `json:"ContactId,omitempty"`
	AccountID         string       `json:"AccountId,omitempty"`
	CustomFields      CustomFields `json:"-"`
}

Directories

Path Synopsis
internal
env

Jump to

Keyboard shortcuts

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