Skip to main content

SalesforceRestClient

Struct SalesforceRestClient 

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

Salesforce REST API client.

Provides typed methods for all REST API operations:

  • CRUD operations on SObjects
  • SOQL queries with automatic pagination
  • SOSL search
  • Describe operations
  • Composite API
  • SObject Collections

§Example

use sf_rest::SalesforceRestClient;

let client = SalesforceRestClient::new(
    "https://myorg.my.salesforce.com",
    "access_token_here",
)?;

// Query
let accounts: Vec<Account> = client.query_all("SELECT Id, Name FROM Account").await?;

// Create
let id = client.create("Account", &json!({"Name": "New Account"})).await?;

// Update
client.update("Account", &id, &json!({"Name": "Updated"})).await?;

// Delete
client.delete("Account", &id).await?;

Implementations§

Source§

impl SalesforceRestClient

Source

pub async fn get_blob( &self, sobject: &str, id: &str, blob_field: &str, ) -> Result<Vec<u8>, Error>

Get binary blob content from an SObject field (e.g., Attachment body, Document body).

Source

pub async fn get_rich_text_image( &self, sobject: &str, id: &str, field_name: &str, content_reference_id: &str, ) -> Result<Vec<u8>, Error>

Get a rich text image from an SObject field.

Source

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

Get related records via a relationship field.

Source

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

Get basic info about an SObject type (describe + recent items).

Source§

impl SalesforceRestClient

Source

pub async fn create_multiple<T>( &self, sobject: &str, records: &[T], all_or_none: bool, ) -> Result<Vec<CollectionResult>, Error>
where T: Serialize,

Create multiple records in a single request (up to 200).

Source

pub async fn update_multiple<T>( &self, sobject: &str, records: &[(String, T)], all_or_none: bool, ) -> Result<Vec<CollectionResult>, Error>
where T: Serialize,

Update multiple records in a single request (up to 200).

Source

pub async fn delete_multiple( &self, ids: &[&str], all_or_none: bool, ) -> Result<Vec<CollectionResult>, Error>

Delete multiple records in a single request (up to 200).

Source

pub async fn get_multiple<T>( &self, sobject: &str, ids: &[&str], fields: &[&str], ) -> Result<Vec<T>, Error>

Get multiple records by ID in a single request (up to 2000).

Source§

impl SalesforceRestClient

Source

pub async fn composite( &self, request: &CompositeRequest, ) -> Result<CompositeResponse, Error>

Execute a composite request with multiple subrequests.

The composite API allows up to 25 subrequests in a single API call. Subrequests can reference results from earlier subrequests using @{referenceId}.

Available since API v34.0.

Source

pub async fn composite_batch( &self, request: &CompositeBatchRequest, ) -> Result<CompositeBatchResponse, Error>

Execute a composite batch request with multiple independent subrequests.

The composite batch API executes up to 25 subrequests independently. Unlike the standard composite API, subrequests cannot reference each other’s results.

Available since API v34.0.

Source

pub async fn composite_tree( &self, sobject: &str, request: &CompositeTreeRequest, ) -> Result<CompositeTreeResponse, Error>

Execute a composite tree request to create record hierarchies.

Creates parent records with nested child records in a single request. Supports up to 200 records total across all levels of the hierarchy.

Available since API v42.0.

§Arguments
  • sobject - The parent SObject type (e.g., “Account”)
  • request - The tree request containing parent records and nested children
Source

pub async fn composite_graph( &self, request: &CompositeGraphRequest, ) -> Result<CompositeGraphResponse, Error>

Execute a composite graph request with multiple independent graphs.

Each graph contains a set of composite subrequests that can reference each other within the same graph. Different graphs are independent.

Available since API v50.0.

Source§

impl SalesforceRestClient

Read consent status for an action and a set of IDs.

Write consent for an action (uses PATCH, not POST).

Read consent for multiple actions and IDs.

Source§

impl SalesforceRestClient

Source

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

Create a new record.

Returns the ID of the created record.

Source

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

Get a record by ID.

Optionally specify which fields to retrieve.

Source

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

Update a record.

Source

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

Delete a record.

Source

pub async fn upsert<T>( &self, sobject: &str, external_id_field: &str, external_id_value: &str, record: &T, ) -> Result<UpsertResult, Error>
where T: Serialize,

Upsert a record using an external ID field.

Creates the record if it doesn’t exist, updates it if it does.

Source§

impl SalesforceRestClient

Source

pub async fn describe_global(&self) -> Result<DescribeGlobalResult, Error>

Get a list of all SObjects available in the org.

This is equivalent to calling /services/data/vXX.0/sobjects/.

Source

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

Get detailed metadata for a specific SObject.

This is equivalent to calling /services/data/vXX.0/sobjects/{sobject}/describe.

Source§

impl SalesforceRestClient

Source

pub async fn get_embedded_service_config( &self, config_id: &str, ) -> Result<EmbeddedServiceConfig, Error>

Get embedded service configuration by ID.

Source§

impl SalesforceRestClient

Source

pub async fn list_standard_actions( &self, ) -> Result<InvocableActionCollection, Error>

List all standard invocable actions.

Returns a collection of all standard actions available in the org.

Source

pub async fn list_custom_action_types( &self, ) -> Result<HashMap<String, String>, Error>

List custom invocable action type categories.

Returns a map of category names (e.g., “apex”, “flow”) to their sub-resource URLs. Use list_custom_actions() to get actual actions within a category.

Source

pub async fn list_custom_actions( &self, action_type: &str, ) -> Result<InvocableActionCollection, Error>

List custom invocable actions of a specific type.

§Arguments
  • action_type - The action type category (e.g., “apex”, “flow”)
Source

pub async fn describe_standard_action( &self, action_name: &str, ) -> Result<InvocableActionDescribe, Error>

Describe a standard invocable action.

Source

pub async fn describe_custom_action( &self, action_type: &str, action_name: &str, ) -> Result<InvocableActionDescribe, Error>

Describe a custom invocable action.

Custom actions are organized by type (e.g., “apex”, “flow”). Both the action type and action name are required.

Source

pub async fn invoke_standard_action( &self, action_name: &str, request: &InvocableActionRequest, ) -> Result<Vec<InvocableActionResult>, Error>

Invoke a standard action.

Returns a vector of results (one per input).

Source

pub async fn invoke_custom_action( &self, action_type: &str, action_name: &str, request: &InvocableActionRequest, ) -> Result<Vec<InvocableActionResult>, Error>

Invoke a custom action.

Custom actions are organized by type. Both the action type and action name are required.

Returns a vector of results (one per input).

Source§

impl SalesforceRestClient

Source

pub async fn knowledge_settings(&self) -> Result<KnowledgeSettings, Error>

Get knowledge management settings.

Source

pub async fn knowledge_articles( &self, query: Option<&str>, channel: Option<&str>, ) -> Result<KnowledgeArticlesResponse, Error>

List knowledge articles, optionally filtering by query string and channel.

Source

pub async fn data_category_groups( &self, sobject: Option<&str>, ) -> Result<DataCategoryGroupsResponse, Error>

Get data category groups, optionally filtered by SObject type.

Source

pub async fn data_categories( &self, group: &str, sobject: Option<&str>, ) -> Result<DataCategoriesResponse, Error>

Get data categories within a group, optionally filtered by SObject type.

Source§

impl SalesforceRestClient

Source

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

Get all page layouts for a specific SObject.

This returns metadata about all page layouts configured for the SObject, including sections, rows, items, and field metadata.

§Example
let layouts = client.describe_layouts("Account").await?;
println!("Account layouts: {:?}", layouts);

This is equivalent to calling /services/data/vXX.0/sobjects/{sobject}/describe/layouts.

Source

pub async fn describe_named_layout( &self, sobject: &str, layout_name: &str, ) -> Result<Value, Error>

Get a specific named layout for an SObject.

This returns the layout metadata for a specific named layout.

§Example
let layout = client.describe_named_layout("Account", "MyCustomLayout").await?;
println!("Layout metadata: {:?}", layout);

This is equivalent to calling /services/data/vXX.0/sobjects/{sobject}/describe/namedLayouts/{layoutName}.

Source

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

Get approval process layouts for a specific SObject.

This returns the approval process layout information including approval steps, actions, and field mappings.

§Example
let approval_layouts = client.describe_approval_layouts("Account").await?;
println!("Approval layouts: {:?}", approval_layouts);

This is equivalent to calling /services/data/vXX.0/sobjects/{sobject}/describe/approvalLayouts.

Source

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

Get compact layouts for a specific SObject.

Compact layouts are used in the Salesforce mobile app and Lightning Experience to show a preview of a record in a compact space.

§Example
let compact_layouts = client.describe_compact_layouts("Account").await?;
println!("Compact layouts: {:?}", compact_layouts);

This is equivalent to calling /services/data/vXX.0/sobjects/{sobject}/describe/compactLayouts.

Source

pub async fn describe_global_publisher_layouts(&self) -> Result<Value, Error>

Get global publisher layouts (global quick actions).

This returns global quick actions and publisher layouts that are available across the entire organization, not tied to a specific SObject.

§Example
let global_layouts = client.describe_global_publisher_layouts().await?;
println!("Global layouts: {:?}", global_layouts);

This is equivalent to calling /services/data/vXX.0/sobjects/Global/describe/layouts.

Source§

impl SalesforceRestClient

Source

pub async fn limits(&self) -> Result<Value, Error>

Get API limits for the org.

Source

pub async fn versions(&self) -> Result<Vec<ApiVersion>, Error>

Get available API versions.

Source§

impl SalesforceRestClient

Source

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

List all list views for an SObject.

Source

pub async fn get_list_view( &self, sobject: &str, list_view_id: &str, ) -> Result<ListView, Error>

Get a specific list view by ID.

Source

pub async fn describe_list_view( &self, sobject: &str, list_view_id: &str, ) -> Result<ListViewDescribe, Error>

Describe a list view (get columns, filters, etc.).

Source

pub async fn execute_list_view<T>( &self, sobject: &str, list_view_id: &str, ) -> Result<ListViewResult<T>, Error>

Execute a list view and return its results.

Source§

impl SalesforceRestClient

Source

pub async fn list_process_rules(&self) -> Result<ProcessRuleCollection, Error>

List all process rules.

Source

pub async fn list_process_rules_for_sobject( &self, sobject: &str, ) -> Result<Vec<ProcessRule>, Error>

List process rules for a specific SObject type.

Returns the array of rules for that SObject.

Source

pub async fn trigger_process_rules( &self, request: &ProcessRuleRequest, ) -> Result<ProcessRuleResult, Error>

Trigger process rules for a record.

Source

pub async fn list_pending_approvals( &self, ) -> Result<PendingApprovalCollection, Error>

List pending approval work items.

Source

pub async fn submit_approval( &self, request: &ApprovalRequest, ) -> Result<ApprovalResult, Error>

Submit, approve, or reject an approval request.

The response is an array; this method returns the first element.

Source§

impl SalesforceRestClient

Source

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

Execute a SOQL query.

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 the security utilities:

use busbar_sf_client::security::soql;

// WRONG - vulnerable to injection:
let query = format!("SELECT Id FROM Account WHERE Name = '{}'", user_input);

// CORRECT - properly escaped:
let safe_value = soql::escape_string(user_input);
let query = format!("SELECT Id FROM Account WHERE Name = '{}'", safe_value);
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 query_all_including_deleted<T>( &self, soql: &str, ) -> Result<QueryResult<T>, Error>

Execute a SOQL query including deleted/archived records.

§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 query_more<T>( &self, next_records_url: &str, ) -> Result<QueryResult<T>, Error>

Fetch the next page of query results.

Source§

impl SalesforceRestClient

Source

pub async fn list_global_quick_actions(&self) -> Result<Vec<QuickAction>, Error>

List all global quick actions.

Source

pub async fn describe_global_quick_action( &self, action_name: &str, ) -> Result<QuickActionDescribe, Error>

Describe a global quick action.

Source

pub async fn list_quick_actions( &self, sobject: &str, ) -> Result<Vec<QuickAction>, Error>

List all quick actions available for an SObject.

Source

pub async fn describe_quick_action( &self, sobject: &str, action_name: &str, ) -> Result<QuickActionDescribe, Error>

Describe a specific quick action.

Action names can contain dots for SObject-scoped actions (e.g., FeedItem.TextPost, FeedItem.ContentPost).

Source

pub async fn invoke_quick_action( &self, sobject: &str, action_name: &str, body: &Value, ) -> Result<QuickActionResult, Error>

Invoke a quick action on an SObject.

Action names can contain dots for SObject-scoped actions (e.g., FeedItem.TextPost, FeedItem.ContentPost).

Source§

impl SalesforceRestClient

Source

pub async fn appointment_candidates( &self, request: &AppointmentCandidatesRequest, ) -> Result<AppointmentCandidatesResponse, Error>

Get appointment candidates based on scheduling parameters.

Source

pub async fn appointment_slots(&self, request: &Value) -> Result<Value, Error>

Get appointment slots based on scheduling parameters.

Source§

impl SalesforceRestClient

Source

pub async fn search<T>(&self, sosl: &str) -> Result<SearchResult<T>, Error>

Execute a SOSL search.

§Security

IMPORTANT: If you are including user-provided values in the search term, you MUST escape them. Use busbar_sf_client::security::soql::escape_string() for string values in SOSL queries.

Execute a parameterized search request.

This provides a structured alternative to raw SOSL queries, with support for filtering by SObject type, field selection, and pagination.

Source

pub async fn search_suggestions( &self, query: &str, sobject: &str, ) -> Result<SearchSuggestionResult, Error>

Get search suggestions (auto-complete) for a query string and SObject type.

Returns suggested records matching the query prefix.

Source

pub async fn search_scope_order(&self) -> Result<Vec<ScopeEntity>, Error>

Get the search scope order for the current user.

Returns the list of SObjects in the order they appear in the user’s search scope.

Source

pub async fn search_result_layouts( &self, sobjects: &[&str], ) -> Result<Vec<SearchLayoutInfo>, Error>

Get search result layouts for the specified SObject types.

Returns the columns displayed in search results for each SObject type.

Source§

impl SalesforceRestClient

Source

pub async fn tabs(&self) -> Result<Vec<Value>, Error>

Get all tabs available to the current user.

Returns information about all tabs, including custom tabs.

Source

pub async fn theme(&self) -> Result<Value, Error>

Get the current user’s theme information.

Returns theme colors, icons, and other UI customization data.

Source

pub async fn app_menu(&self, app_menu_type: &str) -> Result<Value, Error>

Get the app menu for a specific menu type.

§Arguments
  • app_menu_type - One of: “AppSwitcher”, “Salesforce1”, “NetworkTabs”
Source

pub async fn recent_items(&self) -> Result<Vec<Value>, Error>

Get recently viewed items for the current user.

Returns a list of recently accessed records.

Source

pub async fn relevant_items(&self) -> Result<Value, Error>

Get relevant items for the current user.

Returns items that Salesforce considers relevant based on the user’s activity.

Source

pub async fn compact_layouts(&self, sobject_list: &str) -> Result<Value, Error>

Get compact layouts for multiple SObject types.

§Arguments
  • sobject_list - Comma-separated list of SObject API names (e.g., “Account,Contact”)
Source

pub async fn platform_event_schema( &self, event_name: &str, ) -> Result<Value, Error>

Get the event schema for a platform event.

§Arguments
  • event_name - The platform event API name (e.g., “MyEvent__e”)
Source

pub async fn lightning_toggle_metrics(&self) -> Result<Value, Error>

Get Lightning Experience toggle metrics.

Returns metrics about Lightning Experience vs Classic usage.

Source

pub async fn lightning_usage(&self) -> Result<Value, Error>

Get Lightning Experience usage data.

Returns Lightning Experience usage statistics.

Source§

impl SalesforceRestClient

Source

pub async fn get_deleted( &self, sobject: &str, start: &str, end: &str, ) -> Result<GetDeletedResult, Error>

Get deleted records for an SObject type within a date range.

The start and end parameters should be ISO 8601 date-time strings (e.g., “2024-01-01T00:00:00Z”).

Source

pub async fn get_updated( &self, sobject: &str, start: &str, end: &str, ) -> Result<GetUpdatedResult, Error>

Get updated record IDs for an SObject type within a date range.

The start and end parameters should be ISO 8601 date-time strings (e.g., “2024-01-01T00:00:00Z”).

Source§

impl SalesforceRestClient

Source

pub async fn get_user_password_status( &self, user_id: &str, ) -> Result<UserPasswordStatus, Error>

Get the password expiration status for a user.

Source

pub async fn set_user_password( &self, user_id: &str, request: &SetPasswordRequest, ) -> Result<(), Error>

Set a user’s password.

Source

pub async fn reset_user_password( &self, user_id: &str, ) -> Result<SetPasswordResponse, Error>

Reset a user’s password.

Salesforce generates a new password and returns it in the response. This uses DELETE to trigger the reset.

Source§

impl SalesforceRestClient

Source

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

Create a new REST 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<SalesforceRestClient, Error>

Create a new REST client with custom HTTP configuration.

Source

pub fn from_client(client: SalesforceClient) -> SalesforceRestClient

Create a REST 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>, ) -> SalesforceRestClient

Set the API version.

Trait Implementations§

Source§

impl Clone for SalesforceRestClient

Source§

fn clone(&self) -> SalesforceRestClient

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 SalesforceRestClient

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