Record Management
To create a new ‘Contact’ in Salesforce:
sf.Contact.create({'LastName':'Smith','Email':'example@example.com'})
This will return a dictionary such as {u'errors': [], u'id': u'003e0000003GuNXAA0', u'success': True}
To get a dictionary with all the information regarding that record, use:
contact = sf.Contact.get('003e0000003GuNXAA0')
To get a dictionary with all the information regarding that record, using a custom field that was defined as External ID:
contact = sf.Contact.get_by_custom_id('My_Custom_ID__c', '22')
To change that contact’s last name from ‘Smith’ to ‘Jones’ and add a first name of ‘John’ use:
sf.Contact.update('003e0000003GuNXAA0',{'LastName': 'Jones', 'FirstName': 'John'})
To delete the contact:
sf.Contact.delete('003e0000003GuNXAA0')
To retrieve a list of Contact records deleted over the past 10 days (datetimes are required to be in UTC):
import pytz
import datetime
end = datetime.datetime.now(pytz.UTC) # we need to use UTC as salesforce API requires this!
sf.Contact.deleted(end - datetime.timedelta(days=10), end)
To retrieve a list of Contact records updated over the past 10 days (datetimes are required to be in UTC):
import pytz
import datetime
end = datetime.datetime.now(pytz.UTC) # we need to use UTC as salesforce API requires this
sf.Contact.updated(end - datetime.timedelta(days=10), end)
Note that Update, Delete and Upsert actions return the associated Salesforce HTTP Status Code
Use the same format to create any record, including ‘Account’, ‘Opportunity’, and ‘Lead’. Make sure to have all the required fields for any entry. The Salesforce API has all objects found under ‘Reference -> Standard Objects’ and the required fields can be found there.