The Salesforce client your web app deserves. Async or sync, same API.
import even_simpler_salesforce as esf
auth = esf.ClientCredentials(
domain="https://acme.my.salesforce.com",
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
)
# Logs in on the first call. Refreshes the token for you.
async with esf.AsyncSalesforce(auth) as sf:
# Values are quoted for you: no SOQL injection.
lead = await sf.query_one(
"SELECT Id, Name FROM Lead WHERE Email = {}", email
)
try:
await sf.sobject("Lead").update(lead["Id"], {"Status": "Working"})
except esf.ValidationRuleFailed as exc:
print(exc.message, exc.fields) # one class per Salesforce error
import even_simpler_salesforce as esf
auth = esf.ClientCredentials(
domain="https://acme.my.salesforce.com",
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
)
# Logs in on the first call. Refreshes the token for you.
with esf.Salesforce(auth) as sf:
# Values are quoted for you: no SOQL injection.
lead = sf.query_one(
"SELECT Id, Name FROM Lead WHERE Email = {}", email
)
try:
sf.sobject("Lead").update(lead["Id"], {"Status": "Working"})
except esf.ValidationRuleFailed as exc:
print(exc.message, exc.fields) # one class per Salesforce error