ExForce v0.4.0 ExForce View Source

Simple wrapper for Salesforce REST API.

Installation

The package can be installed by adding ex_force to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_force, "~> 0.3"}
  ]
end

Check out Choosing a Tesla Adapter.

Usage

{:ok, %{instance_url: instance_url} = oauth_response} =
  ExForce.OAuth.get_token(
    "https://login.salesforce.com",
    grant_type: "password",
    client_id: "client_id",
    client_secret: "client_secret",
    username: "username",
    password: "password" <> "security_token"
  )

{:ok, version_maps} = ExForce.versions(instance_url)
latest_version = version_maps |> Enum.map(&Map.fetch!(&1, "version")) |> List.last()

client = ExForce.build_client(oauth_response, api_version: latest_version)

names =
  ExForce.query_stream(client, "SELECT Name FROM Account")
  |> Stream.map(&Map.fetch!(&1.data, "Name"))
  |> Stream.take(50)
  |> Enum.to_list()

Link to this section Summary

Functions

Retrieves basic metadata for the specific SObject.

Lists the available objects.

Retrieves extended metadata for the specified SObject.

Retrieves a SObject by ID.

Retrieves a SObject based on the value of a specified extneral ID field.

Excute the SOQL query and get the result of it.

Excute the SOQL query and get the result of it, including deleted or archived objects.

Retrieve additional query results for the specified query ID.

Lists available resources for the specific API version.

Returns Enumerable.t from the QueryResult.

Use the Composite API to update multiple records (up to 200) in one call, returning a list of SaveResult objects. You can choose whether to roll back the entire request when an error occurs. If more than 200 records need to be updated at once, try using the Bulk API. See Update Multiple Records with Fewer Round-Trips

Lists available REST API versions at an instance.

Link to this section Types

Link to this type

field_name()

View Source
field_name() :: String.t()
Link to this type

query_id()

View Source
query_id() :: String.t()
Link to this type

sobject()

View Source
sobject() :: %{id: String.t(), attributes: %{type: String.t()}}
Link to this type

sobject_id()

View Source
sobject_id() :: String.t()
Link to this type

sobject_name()

View Source
sobject_name() :: String.t()

Link to this section Functions

Link to this function

basic_info(client, name)

View Source
basic_info(client(), sobject_name()) :: {:ok, map()} | {:error, any()}

Retrieves basic metadata for the specific SObject.

See SObject Basic Information

Link to this function

build_client(instance_url)

View Source

See ExForce.Client.build_client/1.

Link to this function

build_client(instance_url, opts)

View Source

See ExForce.Client.build_client/2.

Link to this function

create_sobject(client, name, attrs)

View Source
create_sobject(client(), sobject_name(), map()) ::
  {:ok, sobject_id()} | {:error, any()}

Creates a SObject.

See SObject Rows

Link to this function

delete_sobject(client, id, name)

View Source
delete_sobject(client(), sobject_id(), sobject_name()) :: :ok | {:error, any()}

Deletes a SObject.

SObject Rows

Link to this function

describe_global(client)

View Source
describe_global(client()) :: {:ok, map()} | {:error, any()}

Lists the available objects.

See Describe Global

Link to this function

describe_sobject(client, name)

View Source
describe_sobject(client(), sobject_name()) :: {:ok, map()} | {:error, any()}

Retrieves extended metadata for the specified SObject.

See SObject Describe

Link to this function

get_sobject(client, id, name, fields)

View Source
get_sobject(client(), sobject_id(), sobject_name(), list()) ::
  {:ok, ExForce.SObject.t()} | {:error, any()}

Retrieves a SObject by ID.

See SObject Rows

Link to this function

get_sobject_by_external_id(client, field_value, field_name, sobject_name)

View Source
get_sobject_by_external_id(client(), any(), field_name(), sobject_name()) ::
  {:ok, ExForce.SObject.t()} | {:error, any()}

Retrieves a SObject based on the value of a specified extneral ID field.

See SObject Rows by External ID

Link to this function

get_sobject_by_relationship(client, id, sobject_name, field_name, fields)

View Source
get_sobject_by_relationship(
  client(),
  sobject_id(),
  sobject_name(),
  field_name(),
  [field_name()]
) :: {:ok, ExForce.SObject.t() | ExForce.QueryResult.t()} | {:error, any()}

Retrieves a SObject by relationship field.

See SObject Relationships

Link to this function

query(client, soql)

View Source
query(client(), soql()) :: {:ok, ExForce.QueryResult.t()} | {:error, any()}

Excute the SOQL query and get the result of it.

Query

Link to this function

query_all(client, soql)

View Source
query_all(client(), soql()) :: {:ok, ExForce.QueryResult.t()} | {:error, any()}

Excute the SOQL query and get the result of it, including deleted or archived objects.

QueryAll

Link to this function

query_all_stream(client, soql)

View Source
query_all_stream(client(), soql()) :: Enumerable.t()
Link to this function

query_retrieve(client, query_id_or_url)

View Source
query_retrieve(client(), query_id() | String.t()) ::
  {:ok, ExForce.QueryResult.t()} | {:error, any()}

Retrieve additional query results for the specified query ID.

Query

Link to this function

query_stream(client, soql)

View Source
query_stream(client(), soql()) :: Enumerable.t()
Link to this function

resources(client, version)

View Source
resources(client(), String.t()) :: {:ok, map()} | {:error, any()}

Lists available resources for the specific API version.

See Resources by Version

Link to this function

stream_query_result(client, qr)

View Source
stream_query_result(client(), ExForce.QueryResult.t()) :: Enumerable.t()

Returns Enumerable.t from the QueryResult.

Link to this function

update_sobject(client, id, name, attrs)

View Source
update_sobject(client(), sobject_id(), sobject_name(), map()) ::
  :ok | {:error, any()}

Updates a SObject.

See SObject Rows

Link to this function

update_sobjects(client, records, all_or_none \\ false)

View Source
update_sobjects(client(), records :: [sobject()], all_or_none :: boolean()) ::
  {:ok, any()} | {:error, any()}

Use the Composite API to update multiple records (up to 200) in one call, returning a list of SaveResult objects. You can choose whether to roll back the entire request when an error occurs. If more than 200 records need to be updated at once, try using the Bulk API. See Update Multiple Records with Fewer Round-Trips

Link to this function

versions(instance_url)

View Source
versions(String.t()) :: {:ok, [map()]} | {:error, any()}

Lists available REST API versions at an instance.

See Versions