https://prefect.io logo
Title
a

Amey Desai

11/14/2022, 6:09 PM
Has anybody used Prefect to write data into Salesforce ?
1
b

Bianca Hoch

11/14/2022, 6:09 PM
Hello Amey, we do this quite a lot here at Prefect.
a

Amey Desai

11/14/2022, 6:10 PM
Are there examples that I can see ?
b

Bianca Hoch

11/14/2022, 6:13 PM
I can take a look. Are you utilizing 2.0? or 1.0?
a

Amey Desai

11/14/2022, 6:13 PM
2.0
b

Bianca Hoch

11/14/2022, 6:13 PM
Thank you! Also could you tell us a bit more about what you'd like to accomplish?
a

Amey Desai

11/14/2022, 6:14 PM
Writing data into customers salesforce, effectively reverse ETL.
b

Bianca Hoch

11/14/2022, 6:35 PM
To get you started, here is a helpful package that our engineers use to interact with the Salesforce REST API.
As soon as we find a 2.0 example we'll share here
Here is a snippet which you can use to
create
and
get
records using the simple-salesforce package:
from prefect import flow, task
from simple_salesforce import Salesforce
import requests

@task()
def create_sf_account(un, pw, tk):
     session = requests.Session()
# manipulate the session instance (optional)
       sf = Salesforce(
   username=un, password=pw, token=tk)
        sf.Account.create({'Name':'Smith','Email':'<mailto:example@example.com|example@example.com>'})


@task()
def get_sf_data(un, pw, tk):
    sf = Salesforce(username=un, password=pw, security_token=tk, domain="test")
    query = f"SELECT Id, Name FROM Accounts"
    data = sf.query(query)
    records = data["records"]
    return records

@flow
def salesforce_example():
   salesforce_accounts = get_sf_data(username, password, token)
a

Amey Desai

11/14/2022, 6:49 PM
that's very helpful, thank you, curious, are there any plans for prefect to have prefect-salesforce library ? like prefect-bigquery or prefect-airbyte ?
k

Kalise Richmond

11/14/2022, 7:21 PM
This is a great idea! We have a collections-template that you could use if you're looking at building the integration yourself. You can also ask about integrations in the #prefect-integrations channel