2 releases

✓ Uses Rust 2018 edition

0.1.1 Oct 7, 2019
0.1.0 Oct 6, 2019

#306 in #api

MIT license

19KB
424 lines

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

Rustforce

Salesforce Client for Rust

Usage

use rustforce::Client;
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,
}

fn main() {
    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);

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

Authentication

Username Password Flow

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

[WIP]Authorization Code Grant

Query Records

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

Query All Records

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

Find By Id

let r: Result<Account, Vec<ErrorResponse>> = client.find_by_id("Account", "{sf_id}");

Create Record

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

Update Record

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

Upsert Record

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

Delete Record

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

Describe Global

let r = client.describe_global();

Describe SObject

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

Versions

let versions = client.versions();

Search(SOSL)

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

Dependencies

~15MB
~376K SLoC