pub struct ToolingClient { /* private fields */ }Expand description
Salesforce Tooling API client.
Provides typed methods for Tooling API operations:
- Execute anonymous Apex
- Query Apex classes, triggers, and logs
- Manage debug logs and trace flags
- Code coverage information
§Example
use sf_tooling::ToolingClient;
let client = ToolingClient::new(
"https://myorg.my.salesforce.com",
"access_token_here",
)?;
// Execute anonymous Apex
let result = client.execute_anonymous("System.debug('Hello');").await?;
// Query Apex classes
let classes: Vec<ApexClass> = client
.query_all("SELECT Id, Name FROM ApexClass")
.await?;Implementations§
Source§impl ToolingClient
impl ToolingClient
Sourcepub fn new(
instance_url: impl Into<String>,
access_token: impl Into<String>,
) -> Result<ToolingClient, Error>
pub fn new( instance_url: impl Into<String>, access_token: impl Into<String>, ) -> Result<ToolingClient, Error>
Create a new Tooling API 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<ToolingClient, Error>
pub fn with_config( instance_url: impl Into<String>, access_token: impl Into<String>, config: ClientConfig, ) -> Result<ToolingClient, Error>
Create a new Tooling API client with custom HTTP configuration.
Sourcepub fn from_client(client: SalesforceClient) -> ToolingClient
pub fn from_client(client: SalesforceClient) -> ToolingClient
Create a Tooling client from an existing SalesforceClient.
Sourcepub fn inner(&self) -> &SalesforceClient
pub fn inner(&self) -> &SalesforceClient
Get the underlying SalesforceClient.
Sourcepub fn instance_url(&self) -> &str
pub fn instance_url(&self) -> &str
Get the instance URL.
Sourcepub fn api_version(&self) -> &str
pub fn api_version(&self) -> &str
Get the API version.
Sourcepub fn with_api_version(self, version: impl Into<String>) -> ToolingClient
pub fn with_api_version(self, version: impl Into<String>) -> ToolingClient
Set the API version.
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 against the Tooling API.
Returns the first page of results. Use query_all for automatic pagination.
§Security
IMPORTANT: If you are including user-provided values in the WHERE clause, you MUST escape them to prevent SOQL injection attacks:
use busbar_sf_client::security::soql;
// CORRECT - properly escaped:
let safe_name = soql::escape_string(user_input);
let query = format!("SELECT Id FROM ApexClass WHERE Name = '{}'", safe_name);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 return all results (automatic pagination).
§Security
IMPORTANT: Escape user-provided values with busbar_sf_client::security::soql::escape_string()
to prevent SOQL injection attacks. See query() for examples.
Sourcepub async fn execute_anonymous(
&self,
apex_code: &str,
) -> Result<ExecuteAnonymousResult, Error>
pub async fn execute_anonymous( &self, apex_code: &str, ) -> Result<ExecuteAnonymousResult, Error>
Sourcepub async fn get_apex_classes(&self) -> Result<Vec<ApexClass>, Error>
pub async fn get_apex_classes(&self) -> Result<Vec<ApexClass>, Error>
Get all Apex classes in the org.
Sourcepub async fn get_apex_class_by_name(
&self,
name: &str,
) -> Result<Option<ApexClass>, Error>
pub async fn get_apex_class_by_name( &self, name: &str, ) -> Result<Option<ApexClass>, Error>
Get an Apex class by name.
Sourcepub async fn get_apex_class(&self, id: &str) -> Result<ApexClass, Error>
pub async fn get_apex_class(&self, id: &str) -> Result<ApexClass, Error>
Get an Apex class by ID.
Sourcepub async fn get_apex_triggers(&self) -> Result<Vec<ApexTrigger>, Error>
pub async fn get_apex_triggers(&self) -> Result<Vec<ApexTrigger>, Error>
Get all Apex triggers in the org.
Sourcepub async fn get_apex_trigger_by_name(
&self,
name: &str,
) -> Result<Option<ApexTrigger>, Error>
pub async fn get_apex_trigger_by_name( &self, name: &str, ) -> Result<Option<ApexTrigger>, Error>
Get an Apex trigger by name.
Sourcepub async fn get_apex_log_body(&self, log_id: &str) -> Result<String, Error>
pub async fn get_apex_log_body(&self, log_id: &str) -> Result<String, Error>
Get the body of a specific Apex log.
Sourcepub async fn delete_all_apex_logs(&self) -> Result<u32, Error>
pub async fn delete_all_apex_logs(&self) -> Result<u32, Error>
Delete all Apex logs for the current user.
Sourcepub async fn get_code_coverage(
&self,
) -> Result<Vec<ApexCodeCoverageAggregate>, Error>
pub async fn get_code_coverage( &self, ) -> Result<Vec<ApexCodeCoverageAggregate>, Error>
Get code coverage for all Apex classes and triggers.
Sourcepub async fn get_org_wide_coverage(&self) -> Result<f64, Error>
pub async fn get_org_wide_coverage(&self) -> Result<f64, Error>
Get overall org-wide code coverage percentage.
Sourcepub async fn get_trace_flags(&self) -> Result<Vec<TraceFlag>, Error>
pub async fn get_trace_flags(&self) -> Result<Vec<TraceFlag>, Error>
Get all active trace flags.
Sourcepub async fn get_debug_levels(&self) -> Result<Vec<DebugLevel>, Error>
pub async fn get_debug_levels(&self) -> Result<Vec<DebugLevel>, Error>
Get all debug levels.
Sourcepub async fn get<T>(&self, sobject: &str, id: &str) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn get<T>(&self, sobject: &str, id: &str) -> Result<T, Error>where
T: DeserializeOwned,
Get a Tooling API SObject by ID.
Trait Implementations§
Source§impl Clone for ToolingClient
impl Clone for ToolingClient
Source§fn clone(&self) -> ToolingClient
fn clone(&self) -> ToolingClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more