6 releases

0.2.0 Aug 29, 2021
0.1.4 Aug 23, 2020
0.1.2 Feb 26, 2020
0.1.1 Oct 7, 2019

#135 in Web programming

Download history 24/week @ 2021-10-03 51/week @ 2021-10-10 22/week @ 2021-10-17 12/week @ 2021-10-24 13/week @ 2021-10-31 52/week @ 2021-11-07 34/week @ 2021-11-14 20/week @ 2021-11-21 22/week @ 2021-11-28 40/week @ 2021-12-05 53/week @ 2021-12-12 37/week @ 2021-12-19 14/week @ 2021-12-26 44/week @ 2022-01-02 39/week @ 2022-01-09 28/week @ 2022-01-16

125 downloads per month

MIT license

36KB
884 lines

crate-name at crates.io crate-name at docs.rs Rust

Rustforce

Salesforce Client for Rust

Usage

use rustforce::{Client, Error};
use rustforce::response::{QueryResponse, ErrorResponse};
use serde::Deserialize;
use std::env;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Account {
    #[serde(rename = "attributes")]
    attributes: Attribute,
    id: String,
    name: String,
}

#[derive(Deserialize, Debug)]
struct Attribute {
    url: String,
    #[serde(rename = "type")]
    sobject_type: String,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    
    let client_id = env::var("SFDC_CLIENT_ID").unwrap();
    let client_secret = env::var("SFDC_CLIENT_SECRET").unwrap();
    let username = env::var("SFDC_USERNAME").unwrap();
    let password = env::var("SFDC_PASSWORD").unwrap();

    let mut client = Client::new(client_id, client_secret);
    client.login_with_credential(username, password).await?;

    let res: QueryResponse<Account> = client.query("SELECT Id, Name FROM Account WHERE id = '0012K00001drfGYQAY'".to_string()).await?;
    println!("{:?}", res);

    Ok(())
}

Authentication

Username Password Flow

let mut client = Client::new(client_id, client_secret);
client.login_with_credential(username, password).await?;

[WIP]Authorization Code Grant

Refresh Token

let r = client.refresh("xxxx").await?;

Query Records

let r: Result<QueryResponse<Account>, Error> = client.query("SELECT Id, Name FROM Account").await?;

Query All Records

let r: Result<QueryResponse<Account>, Error> = client.query_all("SELECT Id, Name FROM Account").await?;

Find By Id

let r: Result<Account, Error> = client.find_by_id("Account", "{sf_id}").await?;

Create Record

let mut params = HashMap::new();
params.insert("Name", "hello rust");
let r = client.create("Account", params).await?;
println!("{:?}", r);

Update Record

let r = client.update("Account", "{sobject_id}", params).await?;

Upsert Record

let r = client.upsert("Account", "{external_key_name}", "{external_key", params).await?;

Delete Record

let r = client.destroy("Account", "{sobject_id}").await?;

Describe Global

let r = client.describe_global().await?;

Describe SObject

let r = client.describe("Account").await?;

Versions

let versions = client.versions().await?;

Search(SOSL)

let r = client.search("FIND {Rust}").await?;

Dependencies

~3–7MB
~167K SLoC