Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import datetime
- import pandas as pd
- from salesforce_bulk import SalesforceBulk
- # this is the format needed for batch updating
- data = {
- "id": ["xxxxxxxxxx", "xxxxxxxx"],
- # the __c is needed for custom fields
- "field1__c": [1.26, 1.26],
- "field2__c": ["Test", "Test"],
- "field3__c": [
- datetime.datetime.utcnow().strftime(
- format="%Y-%m-%dT%H:%M:%S.%fZ"),
- datetime.datetime.utcnow().strftime(
- format="%Y-%m-%dT%H:%M:%S.%fZ")],
- }
- # create the bulk instance
- bulk = SalesforceBulk(
- # set these env vars
- username=os.environ["SALESFORCE_ID"],
- password=os.environ["SALESFORCE_PASSWORD"],
- security_token=os.environ["SALESFORCE_TOKEN"],
- # if you want to hit your sfdc test env
- sandbox=True
- )
- # turn the data into a dataframe
- df = pd.DataFrame(data)
- # create an update job
- job = bulk.create_update_job("Lead", contentType="CSV", concurrency="Parallel")
- # post the batch
- batch = bulk.post_batch(job, df.to_csv(header=True, index=False))
- # this will pause while the batch resolves (success or failure)
- bulk.wait_for_batch(job, batch)
- # if you want to check the status of the batch
- bulk.batch_status(batch_id=batch, job_id=job)
- # optional: the response produced by processing the batch, handy for debugging
- # if the batch fails
- bulk.get_batch_results(batch_id=batch, job_id=job)
- # close the batch job
- bulk.close_job(job)
Add Comment
Please, Sign In to add comment