Has anybody used Prefect to write data into Salesf...
# prefect-community
a
Has anybody used Prefect to write data into Salesforce ?
1
b
Hello Amey, we do this quite a lot here at Prefect.
a
Are there examples that I can see ?
b
I can take a look. Are you utilizing 2.0? or 1.0?
a
2.0
b
Thank you! Also could you tell us a bit more about what you'd like to accomplish?
a
Writing data into customers salesforce, effectively reverse ETL.
b
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:
Copy code
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
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
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