Capstorm Learning Center

SQLForce makes Python a powerful scripting language for manipulating a Salesforce database.

SQLForce:

  • Installs using a standard "python setup.py install" approach.
  • Supports ANSI like INSERT, UPDATE, DELETE, and SELECT syntax (including SELECT DISTINCT, SELECT UNION, and INSERT..FROM SELECT)
  • Overcomes Salesforce governor restrictions (example: only 200 records can be included in an UPDATE batch)
  • Makes a natural bridge language between Salesforce and virtually any other data repository.
  • Hides many Salesforce govern limits (example: 200 records per update).

Most importantly, SQLForce will save you a lot of time by replacing complicated data import/export operations (using DataLoader or an Excel connector) with short scripts.

Here's a short example: Normalize all versions of Contact.MailingCountry to use 'USA'.

import SQLForce

session = SQLForce.Session('Production', This email address is being protected from spambots. You need JavaScript enabled to view it.', 'MyPassword')

countryNames = ['US', 'U.S.', 'United States', 'America', 'United States of America']

session.runCommands("UPDATE Contact SET MailingCountry='USA' WHERE MailingCountry IN ('" + "','".join(countryNames) + "')" )

 

Creating a SQLForce connection to Salesforce uses one of two patterns: session = SQLForce.Session( "type", username", "password", [,"token"] [, proxyHost=host:port [, proxyUser=user, proxyPassword=password] ] ) session = SQLForce.Session( "ProfileName" ) The first form includes Salesforce credentials as part of the…
This article explains how to read records from Salesforce using SQLForce. Simple Record Selection session.selectRecords() The selectRecords() methods returns data from Salesforce as a list of Python records. This is the most common way to select records. Example: for rec…
SQLForce can be used to update records in Salesforce using two techniques. SQLForce supports a standard ANSI UPDATE statement. This is the best way when many records should receive the same update. SQLForce supports an update() method for when the…
SQLForce can be used to insert records in Salesforce using two techniques. SQLForce supports a standard ANSI INSERT statement.  SQLForce supports an insert() method. Always use this approach when inserting a lot of records. With SQLForce you do not have…
The SQLForce.Attachment reader module can be use to export attachments from Salesforce in a couple of lines of code. Attachments can be read into memory or exported directly to disk. Read Attachments into Memory If an Attachment's unique Salesforce id…
SQLForce can be used to delete records from Salesforce using two techniques. SQLForce supports a standard ANSI DELETE statement.  SQLForce supports a delete() method for when Salesforced record ids are known. With SQLForce you do not have to be concerned…
This article explains how to import attachments to Salesforce using SQLForce. To import an attachment to Salesforce, three things are needed: You need the unique Salesforce id of the parent object that will own the attachment (example: an accountId, opportunityid,…
Most of the time a Python programs knows the structure of the Salesforce table it is manipulating. The SQLForce.Session.describeTable() method is designed for programs that have to discover a table's structure at run-time. The SQLForce.Session.describeTable() method returns a list of…