force

package module
v0.0.0-...-13a7aa0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 License: MIT Imports: 8 Imported by: 3

README

force

force is a Go client library for accessing the Salesforce API.

GoDoc TravisCI Build Status CircleCI Build Status Coverage Status

WARNING: Both the documentation and the package itself is under heavy development and in a very early stage. That means, this repo is full of untested code and the API can break without any further notice. Therefore, it comes with absolutely no warranty at all. Feel free to browse or even contribute to it :)

Usage

import "github.com/jpmonette/force"

Construct a new Force client, then use the various services on the client to access different parts of the Salesforce API. For example, to retrieve query performance feedback:

  c, _ := force.NewClient(client, "http://emea.salesforce.com/")
  explain, err := c.QueryExplain("SELECT Id, Name, OwnerId FROM Account LIMIT 10")

To execute some anonymous Apex code, you can use the ExecuteAnonymous function, part of the Tooling service:

c.Tooling.ExecuteAnonymous("System.debug('Hello world!');")
Authentication

The force library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you. The easiest and recommended way to do this is using the oauth2 library, but you can always use any other library that provides an http.Client.

Roadmap

This library is being initially developed for one of my internal project, so API methods will likely be implemented in the order that they are needed by my project. Eventually, I would like to cover the entire Salesforce API, so contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward.

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Overview

Package force provides access to Salesforce various APIs

Package force provides access to Salesforce various APIs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type Client

type Client struct {

	// Base URL for API requests. Defaults to the production Salesforce API,
	// but can be set to a domain endpoint to use with Salesforce sandboxes.
	// BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating.
	UserAgent string

	// Services used for talking to different parts of the Salesforce API.
	Tooling *ToolingService
	// contains filtered or unexported fields
}

Client is an HTTP client used to interact with the Salesforce API

func NewClient

func NewClient(httpClient *http.Client, instanceUrl string) (*Client, error)

NewClient returns a new Salesforce API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (err error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Query

func (c *Client) Query(query string, v interface{}) (err error)

Query is used for retrieving query performance feedback without executing the query

func (*Client) QueryExplain

func (c *Client) QueryExplain(query string) (explain QueryExplainResponse, err error)

QueryExplain is used for retrieving query performance feedback without executing the query

type CodeCoverageResult

type CodeCoverageResult struct {
	DmlInfo                []CodeLocation `json:"dmlInfo"`
	ID                     string         `json:"id"`
	LocationsNotCovered    []CodeLocation `json:"locationsNotCovered"`
	MethodInfo             []CodeLocation `json:"methodInfo"`
	Name                   string         `json:"name"`
	Namespace              string         `json:"namespace"`
	NumLocations           int            `json:"numLocations"`
	NumLocationsNotCovered int            `json:"numLocationsNotCovered"`
	SoqlInfo               []CodeLocation `json:"soqlInfo"`
	SoslInfo               []CodeLocation `json:"soslInfo"`
	Type                   string         `json:"type"`
}

CodeCoverageResult contains the details of the code coverage for the specified unit tests.

type CodeCoverageWarning

type CodeCoverageWarning struct {
	Id        string `json:"id"`
	Message   string `json:"message"`
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

CodeCoverageWarning contains results include both the total number of lines that could have been executed, as well as the number, line, and column positions of code that was not executed.

type CodeLocation

type CodeLocation struct {
	Column        int     `json:"column"`
	Line          int     `json:"line"`
	NumExecutions int     `json:"numExecutions"`
	Time          float64 `json:"time"`
}

CodeLocation contains if any code is not covered, the line and column of the code not tested, and the number of times the code was executed

type DescribeGlobalResult

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

DescribeGlobalResult represents the response of DescribeGlobal()

type DescribeGlobalSObjectResult

type DescribeGlobalSObjectResult struct {
	Activateable        bool   `json:"activateable"`
	Createable          bool   `json:"createable"`
	Custom              bool   `json:"custom"`
	CustomSetting       bool   `json:"customSetting"`
	Deletable           bool   `json:"deletable"`
	DeprecatedAndHidden bool   `json:"deprecatedAndHidden"`
	FeedEnabled         bool   `json:"feedEnabled"`
	KeyPrefix           string `json:"keyPrefix"`
	Label               string `json:"label"`
	LabelPlural         string `json:"labelPlural"`
	Layoutable          bool   `json:"layoutable"`
	Mergeable           bool   `json:"mergeable"`
	Name                string `json:"name"`
	Queryable           bool   `json:"queryable"`
	Replicateable       bool   `json:"replicateable"`
	Retrieveable        bool   `json:"retrieveable"`
	Searchable          bool   `json:"searchable"`
	Triggerable         bool   `json:"triggerable"`
	Undeletable         bool   `json:"undeletable"`
	Updateable          bool   `json:"updateable"`
}

DescribeGlobalSObjectResult represents the properties for one of the objects available for your organization.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Errors   []struct {
		Message   string `json:"message"`
		Errorcode string `json:"errorCode"`
	}
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ExecuteAnonymousResult

type ExecuteAnonymousResult struct {
	Column              int    `json:"column"`
	CompileProblem      string `json:"compileProblem"`
	Compiled            bool   `json:"compiled"`
	ExceptionMessage    string `json:"exceptionMessage"`
	ExceptionStackTrace string `json:"exceptionStackTrace"`
	Line                int    `json:"line"`
	Success             bool   `json:"success"`
}

ExecuteAnonymousResult specifies information about whether or not the compile and run of the code was successful

type QueryExplainResponse

type QueryExplainResponse struct {
	Plans []struct {
		Cardinality          int      `json:"cardinality"`
		Fields               []string `json:"fields"`
		LeadingOperationType string   `json:"leadingOperationType"`
		RelativeCost         float64  `json:"relativeCost"`
		SobjectCardinality   int      `json:"sobjectCardinality"`
		SobjectType          string   `json:"sobjectType"`
		Notes                []struct {
			Description   string   `json:"description"`
			Fields        []string `json:"fields"`
			TableEnumOrID string   `json:"tableEnumOrId"`
		} `json:"notes"`
	} `json:"plans"`
}

QueryExplainResponse is returned by QueryExplain

type RunTestFailure

type RunTestFailure struct {
	Id         string  `json:"id"`
	Message    string  `json:"message"`
	MethodName string  `json:"methodName"`
	Name       string  `json:"name"`
	Namespace  string  `json:"namespace"`
	SeeAllData string  `json:"seeAllData"`
	StackTrace string  `json:"stackTrace"`
	Time       float64 `json:"time"`
	Type       string  `json:"string"`
}

RunTestFailure contains information about failures during the unit test run.

type RunTestSuccess

type RunTestSuccess struct {
	Id         string  `json:"id"`
	MethodName string  `json:"methodName"`
	Name       string  `json:"name"`
	Namespace  string  `json:"namespace"`
	SeeAllData string  `json:"seeAllData"`
	Time       float64 `json:"time"`
}

RunTestSuccess contains information about successes during the unit test run.

type RunTestsAsynchronousRequest

type RunTestsAsynchronousRequest struct {
	ClassIDs       string `json:"classids,omitempty"`
	SuiteIDs       string `json:"suiteids,omitempty"`
	MaxFailedTests string `json:"maxFailedTests,omitempty"`
	TestLevel      string `json:"testLevel,omitempty"`
}

RunTestsAsynchronousRequest contains a sample request to the runTestAsynchronous method

type RunTestsResult

type RunTestsResult struct {
	ApexLogID            string                `json:"apexLogId"`
	CodeCoverage         []CodeCoverageResult  `json:"codeCoverage"`
	CodeCoverageWarnings []CodeCoverageWarning `json:"codeCoverageWarnings"`
	Failures             []RunTestFailure      `json:"failures"`
	NumFailures          int                   `json:"numFailures"`
	NumTestsRun          int                   `json:"numTestsRun"`
	Successes            []RunTestSuccess      `json:"successes"`
	TotalTime            float64               `json:"totalTime"`
}

RunTestsResult contains information about the execution of unit tests, including whether unit tests were completed successfully, code coverage results, and failures.

type ToolingService

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

ToolingService handles communication with the Tooling API methods of the Salesforce Tooling API.

func (*ToolingService) DescribeGlobal

func (c *ToolingService) DescribeGlobal() (result DescribeGlobalResult, err error)

DescribeGlobal lists the available Tooling API objects and their metadata

func (*ToolingService) ExecuteAnonymous

func (c *ToolingService) ExecuteAnonymous(apex string) (result ExecuteAnonymousResult, err error)

ExecuteAnonymous executes the specified block of Apex anonymously and returns the result.

func (*ToolingService) Query

func (c *ToolingService) Query(soql string, v interface{}) (err error)

Query executes a query against a Tooling API object and returns data that matches the specified criteria.

func (*ToolingService) RunTests

func (c *ToolingService) RunTests(classnames []string) (result RunTestsResult, err error)

RunTests executes the tests in the specified classes using the synchronous test execution mechanism.

func (*ToolingService) RunTestsAsynchronous

func (c *ToolingService) RunTestsAsynchronous(classids []string, suiteids []string, maxFailedTests string, testLevel string) (result string, err error)

func (*ToolingService) Search

func (c *ToolingService) Search(sosl string, v interface{}) (err error)

Search is used to search for records that match a specified text string.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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