salesforce

package
v1.86.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Salesforce Adapter

Entity External IDs

The Entity External ID maps to a Salesforce object (table) name. The adapter constructs SOQL queries as:

SELECT Id,{attributes} FROM {entityExternalID} [WHERE {filter}] ORDER BY Id ASC

Delivered via the Salesforce REST API:

{baseURL}/services/data/v{apiVersion}/query?q={SOQL}

The adapter is open-ended - any valid Salesforce object name (standard or custom) can be used as an entity external ID.

Entity External ID Salesforce Object Description
Account Account Salesforce accounts
Contact Contact Salesforce contacts
User User Salesforce users
Case Case Support cases
CustomObject__c (any custom object) Custom Salesforce objects

How It Works

The Entity External ID is URL-escaped and placed directly into the SOQL FROM clause. The adapter builds a SELECT statement from the configured attribute external IDs plus the required Id field.

Example URL (first page):

https://instance.salesforce.com/services/data/v58.0/query?q=SELECT+Id,CaseNumber,Status+FROM+Case+WHERE+Status+%3D+%27Open%27+ORDER+BY+Id+ASC

Subsequent pages use the cursor URL returned by Salesforce:

https://instance.salesforce.com/services/data/v58.0/query/0r8Hu1lKCluUiC9IMK-200

Required Attribute

Every request must include the attribute with external ID Id - this is Salesforce's universal unique identifier.

Attribute External IDs

Attribute external IDs can be:

  • Plain field names: Id, Name, CustomField__c
  • JSONPath format for relationship traversal: $.Account.Name (up to 5 levels)

Supported API Versions

52.0 through 58.0

Notes

  • Page size range: 200-2000.
  • Filters are keyed by entity external ID in the adapter configuration.

Adding New Entity External IDs

No code changes required. The adapter places any entity external ID directly into the SOQL FROM clause. Simply configure a new entity in SGNL with the Salesforce object API name (e.g., Opportunity, Lead, Task, or a custom object like MyObject__c) and it will work.

To find valid object names, check the Salesforce Object Reference or use the Describe API (/services/data/v{version}/sobjects/). Custom objects always end with __c.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructEndpoint

func ConstructEndpoint(request *Request) string

ConstructEndpoint constructs and returns the endpoint to query the datasource.

func NewAdapter

func NewAdapter(client Client) framework.Adapter[Config]

NewAdapter instantiates a new Adapter.

func ParseResponse

func ParseResponse(body []byte) (objects []map[string]any, nextCursor *string, err *framework.Error)

Types

type Adapter

type Adapter struct {
	SalesforceClient Client
}

Adapter implements the framework.Adapter interface to query pages of objects from datasources.

func (*Adapter) GetPage

func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response

GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.

func (*Adapter) RequestPageFromDatasource

func (a *Adapter) RequestPageFromDatasource(
	ctx context.Context, request *framework.Request[Config],
) framework.Response

RequestPageFromDatasource requests a page of objects from a datasource.

func (*Adapter) ValidateGetPageRequest

func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error

ValidateGetPageRequest validates the fields of the GetPage Request.

type Client

type Client interface {
	GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}

Client is a client that allows querying the Salesforce datasource which contains JSON objects.

func NewClient

func NewClient(client *http.Client) Client

NewClient returns a Client to query the datasource.

type Config

type Config struct {
	// Common configuration
	*config.CommonConfig

	// APIVersion is the Salesforce API version to use for requests.
	APIVersion string `json:"apiVersion,omitempty"`

	// Filters contains a map of filters for each entity associated with this
	// datasource. The key is the entity's external_name, and the value is the filter string.
	Filters map[string]string `json:"filters,omitempty"`
}

Config is the configuration passed in each GetPage calls to the adapter. Adapter configuration example: nolint: godot

{
    "requestTimeoutSeconds": 10,
    "apiVersion": "58.0",
    "filters": {
        "User": "isActive=true",
        "Case": "isClosed=false"
    }
}

func (*Config) Validate

func (c *Config) Validate(_ context.Context) error

ValidateConfig validates that a Config received in a GetPage call is valid.

type Datasource

type Datasource struct {
	Client *http.Client
}

Datasource directly implements a Client interface to allow querying an external datasource.

func (*Datasource) GetPage

func (d *Datasource) GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)

type DatasourceResponse

type DatasourceResponse struct {
	Records        []map[string]any `json:"records"`
	NextRecordsURL *string          `json:"nextRecordsUrl"`
}

type Request

type Request struct {
	// BaseURL is the Base URL of the datasource to query.
	BaseURL string

	// Token is the API token to authenticate a request. This token will be provided in the
	// form "Bearer eyJhbG[...]1LQ".
	Token string

	// PageSize is the maximum number of objects to return from the entity.
	PageSize int64

	// EntityExternalID is the external ID of the entity.
	// The external ID should match the API's resource name.
	EntityExternalID string

	// Cursor identifies the first object of the page to return, as returned by
	// the last request for the entity.
	// nil in the request for the first page.
	Cursor *string

	// Filter contains the optional filter to apply to the current request.
	Filter *string

	// Attributes contains the list of attributes to request along with the current request.
	Attributes []*framework.AttributeConfig

	// APIVersion the API version to use.
	APIVersion string

	// RequestTimeoutSeconds is the timeout duration for requests made to datasources.
	// This should be set to the number of seconds to wait before timing out.
	RequestTimeoutSeconds int
}

Request is a request to Salesforce.

type Response

type Response struct {
	// StatusCode is an HTTP status code.
	StatusCode int

	// RetryAfterHeader is the Retry-After response HTTP header, if set.
	RetryAfterHeader string

	// Objects is the list of
	// May be empty.
	Objects []map[string]any

	// NextCursor is the cursor that identifies the first object of the next page.
	// nil if this is the last page in this full sync.
	NextCursor *string
}

Response is a response returned by the datasource.

Jump to

Keyboard shortcuts

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