ExForce (ExForce v0.4.1) 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"}
]
endCheck 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()Note that streams emit ExForce.SObject or an error tuple.
Link to this section Summary
Functions
Retrieves basic metadata for the specific SObject.
Creates a SObject.
Deletes a 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.
Retrieves a SObject by relationship field.
Excutes the SOQL query and get the result of it.
Excutes the SOQL query and get the result of it, including deleted or archived objects.
Retrieves additional query results for the specified query ID.
Lists available resources for the specific API version.
Returns Enumerable.t from the QueryResult.
Updates a SObject.
Updates multiple SObjects using the Composite API.
Lists available REST API versions at an instance.
Link to this section Types
Link to this section Functions
Specs
basic_info(client(), sobject_name()) :: {:ok, map()} | {:error, any()}
Retrieves basic metadata for the specific SObject.
Specs
create_sobject(client(), sobject_name(), map()) :: {:ok, sobject_id()} | {:error, any()}
Creates a SObject.
See SObject Rows
Specs
delete_sobject(client(), sobject_id(), sobject_name()) :: :ok | {:error, any()}
Deletes a SObject.
Specs
Lists the available objects.
See Describe Global
Specs
describe_sobject(client(), sobject_name()) :: {:ok, map()} | {:error, any()}
Retrieves extended metadata for the specified SObject.
See SObject Describe
Specs
get_sobject(client(), sobject_id(), sobject_name(), list()) :: {:ok, ExForce.SObject.t()} | {:error, any()}
Retrieves a SObject by ID.
See SObject Rows
get_sobject_by_external_id(client, field_value, field_name, sobject_name)
View SourceSpecs
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.
get_sobject_by_relationship(client, id, sobject_name, field_name, fields)
View SourceSpecs
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.
Specs
query(client(), soql()) :: {:ok, ExForce.QueryResult.t()} | {:error, any()}
Excutes the SOQL query and get the result of it.
Specs
query_all(client(), soql()) :: {:ok, ExForce.QueryResult.t()} | {:error, any()}
Excutes the SOQL query and get the result of it, including deleted or archived objects.
Specs
query_all_stream(client(), soql()) :: Enumerable.t()
Specs
query_retrieve(client(), query_id() | String.t()) :: {:ok, ExForce.QueryResult.t()} | {:error, any()}
Retrieves additional query results for the specified query ID.
Specs
query_stream(client(), soql()) :: Enumerable.t()
Specs
Lists available resources for the specific API version.
Specs
stream_query_result(client(), ExForce.QueryResult.t()) :: Enumerable.t()
Returns Enumerable.t from the QueryResult.
Specs
update_sobject(client(), sobject_id(), sobject_name(), map()) :: :ok | {:error, any()}
Updates a SObject.
See SObject Rows
Specs
update_sobjects(client(), records :: [sobject()], all_or_none :: boolean()) :: {:ok, any()} | {:error, any()}
Updates multiple SObjects using the Composite API.
It uses 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.
Specs
Lists available REST API versions at an instance.
See Versions