Guest User

Untitled

a guest
Jun 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import os
  2. import datetime
  3. import pandas as pd
  4. from salesforce_bulk import SalesforceBulk
  5.  
  6. # this is the format needed for batch updating
  7. data = {
  8. "id": ["xxxxxxxxxx", "xxxxxxxx"],
  9. # the __c is needed for custom fields
  10. "field1__c": [1.26, 1.26],
  11. "field2__c": ["Test", "Test"],
  12. "field3__c": [
  13. datetime.datetime.utcnow().strftime(
  14. format="%Y-%m-%dT%H:%M:%S.%fZ"),
  15. datetime.datetime.utcnow().strftime(
  16. format="%Y-%m-%dT%H:%M:%S.%fZ")],
  17. }
  18.  
  19. # create the bulk instance
  20. bulk = SalesforceBulk(
  21. # set these env vars
  22. username=os.environ["SALESFORCE_ID"],
  23. password=os.environ["SALESFORCE_PASSWORD"],
  24. security_token=os.environ["SALESFORCE_TOKEN"],
  25. # if you want to hit your sfdc test env
  26. sandbox=True
  27. )
  28.  
  29.  
  30. # turn the data into a dataframe
  31. df = pd.DataFrame(data)
  32.  
  33. # create an update job
  34. job = bulk.create_update_job("Lead", contentType="CSV", concurrency="Parallel")
  35.  
  36. # post the batch
  37. batch = bulk.post_batch(job, df.to_csv(header=True, index=False))
  38.  
  39. # this will pause while the batch resolves (success or failure)
  40. bulk.wait_for_batch(job, batch)
  41.  
  42. # if you want to check the status of the batch
  43. bulk.batch_status(batch_id=batch, job_id=job)
  44.  
  45. # optional: the response produced by processing the batch, handy for debugging
  46. # if the batch fails
  47. bulk.get_batch_results(batch_id=batch, job_id=job)
  48.  
  49. # close the batch job
  50. bulk.close_job(job)
Add Comment
Please, Sign In to add comment