CLI tool to extract Salesforce data and load into SQLite
npm install salesforce-to-sqlite> A Node.js CLI tool that extracts data from Salesforce and loads it into a SQLite database based on a load plan configuration.
- Extracts data from Salesforce using SF CLI
- Creates SQLite tables automatically based on query results
- Handles Salesforce relationship fields (e.g., Parent.Name becomes Parent_Name in SQLite)
- Automatic data type inference
- Progress logging with colored output
- Verbose mode for debugging
- Node.js (v14 or higher)
- Salesforce CLI (sf) installed and authenticated
- Active Salesforce org connection
``bash`
npm install -g salesforce-to-sqlite
`bash`
sf2sqlite -o
`bash`
sf2sqlite -o myorg@example.com -l load-plan.json -d my-data.db
`bash`
sf2sqlite -o myorg@example.com -l load-plan.json -v
- -o, --org - Salesforce org username or alias (required)-l, --load-plan
- - Path to load plan JSON file (required)-d, --database
- - SQLite database file path (default: salesforce.db)-v, --verbose
- - Enable verbose logging-h, --help
- - Display help information-V, --version
- - Display version number
The load plan is a JSON array of object configurations. Each configuration includes:
`json`
{
"object": "ObjectName",
"compositeKeys": ["Field1", "Field2"],
"query": "SELECT Field1, Field2, Related.Field FROM ObjectName",
"fieldMappings": {
"Field1": "Field1",
"Field2": {
"lookup": {
"object": "RelatedObject",
"key": "KeyField",
"field": "Related.Field"
}
}
}
}
1. Read Load Plan: Parses the JSON configuration file
2. Query Salesforce: Executes each SOQL query using sf data queryAccount.Name
3. Field Name Sanitization: Converts relationship fields (e.g., ) to SQLite-compatible names (Account_Name)
4. Table Creation: Creates SQLite tables with inferred data types
5. Data Insertion: Inserts queried data into SQLite tables
6. Type Conversion: Automatically converts Salesforce data types to SQLite equivalents
Salesforce relationship fields like Parent.Name or Account.Owner.Email are automatically converted to SQLite-compatible field names:
- Parent.Name → Parent_NameAccount.Owner.Email
- → Account_Owner_EmailProduct2.StockKeepingUnit
- → Product2_StockKeepingUnit
| Salesforce Type | SQLite Type | Notes |
|----------------|-------------|-------|
| String/Text | TEXT | Default for most fields |
| Boolean | INTEGER | true=1, false=0 |
| Number (Integer) | INTEGER | Whole numbers |
| Number (Decimal) | REAL | Decimal numbers |
| Date/DateTime | TEXT | ISO format strings |
| ID | TEXT | Salesforce IDs |
`bash`
sf2sqlite -o production-org -l load-plan.json -d catalog.db
`bash`
sf2sqlite -o sandbox -l load-plan.json -v
The tool provides colored console output:
- 🔵 Info messages
- ✅ Success messages
- ⚠️ Warning messages
- ❌ Error messages
At the end, a summary shows:
- Number of successfully processed objects
- Number of failed objects
- Location of the SQLite database file
- Invalid load plan JSON: Exits with error message
- Failed Salesforce queries: Logs warning and continues with next object
- Table creation errors: Logs error and skips object
- Record insertion errors: Logs error but continues with other records
- Large queries use a 50MB buffer for CSV data
- SQLite WAL mode is enabled for better performance
- Batch inserts using transactions for speed
- Progress is logged for each object