Skip to main content

SalesforceClient

Struct SalesforceClient 

Source
pub struct SalesforceClient { /* private fields */ }
Expand description

High-level Salesforce API client.

This client combines credentials with HTTP infrastructure and provides typed methods for making API requests. It’s designed to be used by higher-level API-specific crates (sf-rest, sf-bulk, etc.).

§Security

The access token is redacted in Debug output to prevent accidental exposure in logs.

§Example

use sf_client::SalesforceClient;
use sf_auth::SalesforceCredentials;

let creds = SalesforceCredentials::from_env()?;
let client = SalesforceClient::new(creds)?;

// GET with typed response
let user: UserInfo = client.get_json("/services/oauth2/userinfo").await?;

// POST with body and typed response
let result: CreateResult = client
    .post_json("/services/data/v62.0/sobjects/Account", &account)
    .await?;

Implementations§

Source§

impl SalesforceClient

Source

pub fn new( instance_url: impl Into<String>, access_token: impl Into<String>, ) -> Result<SalesforceClient, Error>

Create a new Salesforce client with the given instance URL and access token.

Source

pub fn with_config( instance_url: impl Into<String>, access_token: impl Into<String>, config: ClientConfig, ) -> Result<SalesforceClient, Error>

Create a new Salesforce client with custom configuration.

Source

pub fn with_api_version(self, version: impl Into<String>) -> SalesforceClient

Set the API version (e.g., “62.0”).

Source

pub fn instance_url(&self) -> &str

Get the instance URL.

Source

pub fn access_token(&self) -> &str

Get the access token.

Source

pub fn api_version(&self) -> &str

Get the API version.

Source

pub fn url(&self, path: &str) -> String

Build the full URL for a path.

If the path starts with /, it’s appended to the instance URL. Otherwise, it’s assumed to be a full URL.

Source

pub fn rest_url(&self, path: &str) -> String

Build the REST API URL for a path.

Example: rest_url("sobjects/Account") -> /services/data/v62.0/sobjects/Account

Source

pub fn tooling_url(&self, path: &str) -> String

Build the Tooling API URL for a path.

Example: tooling_url("sobjects/ApexClass") -> /services/data/v62.0/tooling/sobjects/ApexClass

Source

pub fn metadata_url(&self) -> String

Build the Metadata API URL (SOAP endpoint).

Source

pub fn bulk_url(&self, path: &str) -> String

Build the Bulk API 2.0 URL for a path.

Source

pub fn get(&self, url: &str) -> RequestBuilder

Create a GET request builder with authentication.

Source

pub fn post(&self, url: &str) -> RequestBuilder

Create a POST request builder with authentication.

Source

pub fn patch(&self, url: &str) -> RequestBuilder

Create a PATCH request builder with authentication.

Source

pub fn put(&self, url: &str) -> RequestBuilder

Create a PUT request builder with authentication.

Source

pub fn delete(&self, url: &str) -> RequestBuilder

Create a DELETE request builder with authentication.

Source

pub async fn execute(&self, request: RequestBuilder) -> Result<Response, Error>

Execute a request and return the raw response.

Source

pub async fn get_json<T>(&self, url: &str) -> Result<T, Error>

GET request with JSON response deserialization.

Source

pub async fn rest_get<T>(&self, path: &str) -> Result<T, Error>

GET request to REST API with JSON response.

Source

pub async fn tooling_get<T>(&self, path: &str) -> Result<T, Error>

GET request to Tooling API with JSON response.

Source

pub async fn post_json<T, B>(&self, url: &str, body: &B) -> Result<T, Error>

POST request with JSON body and response.

Source

pub async fn rest_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>

POST request to REST API with JSON body and response.

Source

pub async fn tooling_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>

POST request to Tooling API with JSON body and response.

Source

pub async fn patch_json<B>(&self, url: &str, body: &B) -> Result<(), Error>
where B: Serialize,

PATCH request with JSON body and optional response.

Source

pub async fn rest_patch<B>(&self, path: &str, body: &B) -> Result<(), Error>
where B: Serialize,

PATCH request to REST API with JSON body.

Source

pub async fn delete_request(&self, url: &str) -> Result<(), Error>

DELETE request.

Source

pub async fn rest_delete(&self, path: &str) -> Result<(), Error>

DELETE request to REST API.

Source

pub async fn get_json_if_changed<T>( &self, url: &str, etag: &str, ) -> Result<Option<(T, Option<String>)>, Error>

GET request with If-None-Match header (ETag caching). Returns None if the resource hasn’t changed (304 response).

Source

pub async fn get_json_if_modified<T>( &self, url: &str, since: &str, ) -> Result<Option<(T, Option<String>)>, Error>

GET request with If-Modified-Since header. Returns None if the resource hasn’t changed (304 response).

Source

pub async fn query<T>(&self, soql: &str) -> Result<QueryResult<T>, Error>

Execute a SOQL query via REST API.

Source

pub async fn tooling_query<T>( &self, soql: &str, ) -> Result<QueryResult<T>, Error>

Execute a SOQL query via Tooling API.

Source

pub async fn query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>

Execute a SOQL query and automatically fetch all pages.

Source

pub async fn tooling_query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>

Execute a Tooling API query and automatically fetch all pages.

Trait Implementations§

Source§

impl Clone for SalesforceClient

Source§

fn clone(&self) -> SalesforceClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SalesforceClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more