Skip to main content

ToolingClient

Struct ToolingClient 

Source
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

Source

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.

Source

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.

Source

pub fn from_client(client: SalesforceClient) -> ToolingClient

Create a Tooling client from an existing SalesforceClient.

Source

pub fn inner(&self) -> &SalesforceClient

Get the underlying SalesforceClient.

Source

pub fn instance_url(&self) -> &str

Get the instance URL.

Source

pub fn api_version(&self) -> &str

Get the API version.

Source

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

Set the API version.

Source

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

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);
Source

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

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.

Source

pub async fn execute_anonymous( &self, apex_code: &str, ) -> Result<ExecuteAnonymousResult, Error>

Execute anonymous Apex code.

§Example
let result = client.execute_anonymous("System.debug('Hello World');").await?;
if result.success {
    println!("Execution successful");
} else if let Some(err) = result.compile_problem {
    println!("Compilation error: {}", err);
}
Source

pub async fn get_apex_classes(&self) -> Result<Vec<ApexClass>, Error>

Get all Apex classes in the org.

Source

pub async fn get_apex_class_by_name( &self, name: &str, ) -> Result<Option<ApexClass>, Error>

Get an Apex class by name.

Source

pub async fn get_apex_class(&self, id: &str) -> Result<ApexClass, Error>

Get an Apex class by ID.

Source

pub async fn get_apex_triggers(&self) -> Result<Vec<ApexTrigger>, Error>

Get all Apex triggers in the org.

Source

pub async fn get_apex_trigger_by_name( &self, name: &str, ) -> Result<Option<ApexTrigger>, Error>

Get an Apex trigger by name.

Source

pub async fn get_apex_logs( &self, limit: Option<u32>, ) -> Result<Vec<ApexLog>, Error>

Get recent Apex logs.

§Arguments
  • limit - Maximum number of logs to return (defaults to 20)
Source

pub async fn get_apex_log_body(&self, log_id: &str) -> Result<String, Error>

Get the body of a specific Apex log.

Source

pub async fn delete_apex_log(&self, log_id: &str) -> Result<(), Error>

Delete an Apex log.

Source

pub async fn delete_all_apex_logs(&self) -> Result<u32, Error>

Delete all Apex logs for the current user.

Source

pub async fn get_code_coverage( &self, ) -> Result<Vec<ApexCodeCoverageAggregate>, Error>

Get code coverage for all Apex classes and triggers.

Source

pub async fn get_org_wide_coverage(&self) -> Result<f64, Error>

Get overall org-wide code coverage percentage.

Source

pub async fn get_trace_flags(&self) -> Result<Vec<TraceFlag>, Error>

Get all active trace flags.

Source

pub async fn get_debug_levels(&self) -> Result<Vec<DebugLevel>, Error>

Get all debug levels.

Source

pub async fn get<T>(&self, sobject: &str, id: &str) -> Result<T, Error>

Get a Tooling API SObject by ID.

Source

pub async fn create<T>( &self, sobject: &str, record: &T, ) -> Result<String, Error>
where T: Serialize,

Create a Tooling API SObject.

Source

pub async fn delete(&self, sobject: &str, id: &str) -> Result<(), Error>

Delete a Tooling API SObject.

Trait Implementations§

Source§

impl Clone for ToolingClient

Source§

fn clone(&self) -> ToolingClient

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 ToolingClient

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