-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding request_sobject_by_external_id function #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ defmodule ExForce do | |
@type soql :: String.t() | ||
@type query_id :: String.t() | ||
@type sobject :: %{id: String.t(), attributes: %{type: String.t()}} | ||
@type method :: Atom.t() | ||
|
||
defdelegate build_client(instance_url), to: Client | ||
defdelegate build_client(instance_url, opts), to: Client | ||
|
@@ -160,6 +161,30 @@ defmodule ExForce do | |
do: | ||
do_get_sobject(client, "sobjects/#{sobject_name}/#{field_name}/#{URI.encode(field_value)}") | ||
|
||
@doc """ | ||
Makes a request to a SObject based on the value of a specified extneral ID field. Works similarly to get_sobject_by_external_id, but accepts methods other than GET. | ||
|
||
See [SObject Rows by External ID](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_upsert.htm) | ||
Also [Insert or Update (Upsert) a Record Using an External ID](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm) | ||
""" | ||
@spec request_sobject_by_external_id(client, method, any, field_name, sobject_name, map) :: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm.. so Hm.. I'm slightly more inclined to have separate functions instead of one function taking
and they share the same function. Because choosing the HTTP request ( Any thought? |
||
{:ok, map} | {:error, any} | ||
def request_sobject_by_external_id( | ||
client, | ||
method, | ||
field_value, | ||
field_name, | ||
sobject_name, | ||
attrs | ||
), | ||
do: | ||
do_request_sobject( | ||
client, | ||
method, | ||
"sobjects/#{sobject_name}/#{field_name}/#{URI.encode(field_value)}", | ||
attrs | ||
) | ||
|
||
@doc """ | ||
Retrieves a SObject by relationship field. | ||
|
||
|
@@ -206,6 +231,19 @@ defmodule ExForce do | |
end | ||
end | ||
|
||
defp do_request_sobject(client, method, path, attrs) do | ||
case ExForce.Client.request(client, %ExForce.Request{ | ||
method: method, | ||
url: path, | ||
body: attrs | ||
}) do | ||
{:ok, %ExForce.Response{status: 200, body: body}} -> {:ok, body} | ||
{:ok, %ExForce.Response{status: 201, body: body}} -> {:ok, body} | ||
{:ok, %ExForce.Response{body: body}} -> {:error, body} | ||
{:error, _} = other -> other | ||
end | ||
end | ||
|
||
defp build_fields_query([]), do: [] | ||
defp build_fields_query(fields), do: [fields: Enum.join(fields, ",")] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please make following small changes?
get_sobject_by_external_id/4
) so that the generated doc has the proper link