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
impl SalesforceClient
Sourcepub fn new(
instance_url: impl Into<String>,
access_token: impl Into<String>,
) -> Result<SalesforceClient, Error>
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.
Sourcepub fn with_config(
instance_url: impl Into<String>,
access_token: impl Into<String>,
config: ClientConfig,
) -> Result<SalesforceClient, Error>
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.
Sourcepub fn with_api_version(self, version: impl Into<String>) -> SalesforceClient
pub fn with_api_version(self, version: impl Into<String>) -> SalesforceClient
Set the API version (e.g., “62.0”).
Sourcepub fn instance_url(&self) -> &str
pub fn instance_url(&self) -> &str
Get the instance URL.
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the access token.
Sourcepub fn api_version(&self) -> &str
pub fn api_version(&self) -> &str
Get the API version.
Sourcepub fn url(&self, path: &str) -> String
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.
Sourcepub fn rest_url(&self, path: &str) -> String
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
Sourcepub fn tooling_url(&self, path: &str) -> String
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
Sourcepub fn metadata_url(&self) -> String
pub fn metadata_url(&self) -> String
Build the Metadata API URL (SOAP endpoint).
Sourcepub fn get(&self, url: &str) -> RequestBuilder
pub fn get(&self, url: &str) -> RequestBuilder
Create a GET request builder with authentication.
Sourcepub fn post(&self, url: &str) -> RequestBuilder
pub fn post(&self, url: &str) -> RequestBuilder
Create a POST request builder with authentication.
Sourcepub fn patch(&self, url: &str) -> RequestBuilder
pub fn patch(&self, url: &str) -> RequestBuilder
Create a PATCH request builder with authentication.
Sourcepub fn put(&self, url: &str) -> RequestBuilder
pub fn put(&self, url: &str) -> RequestBuilder
Create a PUT request builder with authentication.
Sourcepub fn delete(&self, url: &str) -> RequestBuilder
pub fn delete(&self, url: &str) -> RequestBuilder
Create a DELETE request builder with authentication.
Sourcepub async fn execute(&self, request: RequestBuilder) -> Result<Response, Error>
pub async fn execute(&self, request: RequestBuilder) -> Result<Response, Error>
Execute a request and return the raw response.
Sourcepub async fn get_json<T>(&self, url: &str) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn get_json<T>(&self, url: &str) -> Result<T, Error>where
T: DeserializeOwned,
GET request with JSON response deserialization.
Sourcepub async fn rest_get<T>(&self, path: &str) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn rest_get<T>(&self, path: &str) -> Result<T, Error>where
T: DeserializeOwned,
GET request to REST API with JSON response.
Sourcepub async fn tooling_get<T>(&self, path: &str) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn tooling_get<T>(&self, path: &str) -> Result<T, Error>where
T: DeserializeOwned,
GET request to Tooling API with JSON response.
Sourcepub async fn post_json<T, B>(&self, url: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
pub async fn post_json<T, B>(&self, url: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
POST request with JSON body and response.
Sourcepub async fn rest_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
pub async fn rest_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
POST request to REST API with JSON body and response.
Sourcepub async fn tooling_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
pub async fn tooling_post<T, B>(&self, path: &str, body: &B) -> Result<T, Error>where
T: DeserializeOwned,
B: Serialize,
POST request to Tooling API with JSON body and response.
Sourcepub async fn patch_json<B>(&self, url: &str, body: &B) -> Result<(), Error>where
B: Serialize,
pub async fn patch_json<B>(&self, url: &str, body: &B) -> Result<(), Error>where
B: Serialize,
PATCH request with JSON body and optional response.
Sourcepub async fn rest_patch<B>(&self, path: &str, body: &B) -> Result<(), Error>where
B: Serialize,
pub async fn rest_patch<B>(&self, path: &str, body: &B) -> Result<(), Error>where
B: Serialize,
PATCH request to REST API with JSON body.
Sourcepub async fn get_json_if_changed<T>(
&self,
url: &str,
etag: &str,
) -> Result<Option<(T, Option<String>)>, Error>where
T: DeserializeOwned,
pub async fn get_json_if_changed<T>(
&self,
url: &str,
etag: &str,
) -> Result<Option<(T, Option<String>)>, Error>where
T: DeserializeOwned,
GET request with If-None-Match header (ETag caching). Returns None if the resource hasn’t changed (304 response).
Sourcepub async fn get_json_if_modified<T>(
&self,
url: &str,
since: &str,
) -> Result<Option<(T, Option<String>)>, Error>where
T: DeserializeOwned,
pub async fn get_json_if_modified<T>(
&self,
url: &str,
since: &str,
) -> Result<Option<(T, Option<String>)>, Error>where
T: DeserializeOwned,
GET request with If-Modified-Since header. Returns None if the resource hasn’t changed (304 response).
Sourcepub async fn query<T>(&self, soql: &str) -> Result<QueryResult<T>, Error>where
T: DeserializeOwned,
pub async fn query<T>(&self, soql: &str) -> Result<QueryResult<T>, Error>where
T: DeserializeOwned,
Execute a SOQL query via REST API.
Sourcepub async fn tooling_query<T>(
&self,
soql: &str,
) -> Result<QueryResult<T>, Error>where
T: DeserializeOwned,
pub async fn tooling_query<T>(
&self,
soql: &str,
) -> Result<QueryResult<T>, Error>where
T: DeserializeOwned,
Execute a SOQL query via Tooling API.
Sourcepub async fn query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>where
T: DeserializeOwned + Clone,
pub async fn query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>where
T: DeserializeOwned + Clone,
Execute a SOQL query and automatically fetch all pages.
Sourcepub async fn tooling_query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>where
T: DeserializeOwned + Clone,
pub async fn tooling_query_all<T>(&self, soql: &str) -> Result<Vec<T>, Error>where
T: DeserializeOwned + Clone,
Execute a Tooling API query and automatically fetch all pages.
Trait Implementations§
Source§impl Clone for SalesforceClient
impl Clone for SalesforceClient
Source§fn clone(&self) -> SalesforceClient
fn clone(&self) -> SalesforceClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more