0% found this document useful (0 votes)
0 views5 pages

Salesforce Rest Ops Documentation EN

The InForce CLI Tool documentation details the functionality of the `rest_ops.py` module for exporting Salesforce data to CSV using SOQL queries via the REST API. It includes sections on the main function `export_soql`, expected outputs, error handling, and best practices for usage. Example usage demonstrates how to export Account records filtered by Industry to a specified CSV file.

Uploaded by

juliomontoya7411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

Salesforce Rest Ops Documentation EN

The InForce CLI Tool documentation details the functionality of the `rest_ops.py` module for exporting Salesforce data to CSV using SOQL queries via the REST API. It includes sections on the main function `export_soql`, expected outputs, error handling, and best practices for usage. Example usage demonstrates how to export Account records filtered by Industry to a specified CSV file.

Uploaded by

juliomontoya7411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

InForce CLI Tool - Complete Documentation

Salesforce REST Export - Module Documentation

Comprehensive documentation for SOQL export operations via REST API.

Page 1
InForce CLI Tool - Complete Documentation

Table of Contents

1. Introduction

2. Function Overview

2.1 export_soql

3. Detailed Workflow

4. Arguments Explained

5. Expected Output

6. Error Handling

7. Best Practices

8. Example Usage

Page 2
InForce CLI Tool - Complete Documentation

1. Introduction

The `rest_ops.py` module provides functionality for exporting Salesforce data to a CSV file using

SOQL queries via the REST API. It is designed to be lightweight, efficient, and handle query errors

gracefully.

2. Function Overview
2.1 export_soql

Main function of this module.

Signature:

export_soql(conn, soql_query: str, output_path: str)

Description:

Executes a SOQL query using a valid Salesforce connection and exports the result to a CSV file.

3. Detailed Workflow

1. Calls `query_all()` on the Salesforce connection object using the given SOQL query.

2. Catches malformed queries using `SalesforceMalformedRequest`.

3. Extracts records from the response, omitting metadata like 'attributes'.

4. Writes a CSV file with fieldnames derived from the first record.

5. Each record is written row by row.

This function uses UTF-8 encoding to support special characters in the exported data.

4. Arguments Explained

Page 3
InForce CLI Tool - Complete Documentation

- conn: A valid authenticated Salesforce connection object.

- soql_query: A string containing a valid SOQL statement.

- output_path: The file path where the resulting CSV will be saved.

5. Expected Output

- A CSV file saved to `output_path` containing the results of the SOQL query.

- Column headers will match the selected fields in the SOQL query.

- Nested metadata (like 'attributes') will be excluded.

- If no records are found, a message "No records Found" is printed and no file is created.

6. Error Handling

Handles malformed SOQL queries using a try/except block.

Example Error:

SalesforceMalformedRequest: [{'message': 'unexpected token:', 'errorCode':

'MALFORMED_QUERY'}]

Fix:

Ensure the SOQL syntax is correct, fields exist, and API names are case-sensitive.

7. Best Practices

- Validate SOQL queries in Salesforce Workbench before running them.

- Always sanitize or validate output paths to avoid file overwrite or path issues.

- Log the query and record count if integrating into larger systems.

Page 4
InForce CLI Tool - Complete Documentation

- Avoid SELECT *; always specify the fields you need.

8. Example Usage

from simple_salesforce import Salesforce

from rest_ops import export_soql

sf = Salesforce(username='user', password='pass', security_token='token')

query = "SELECT Id, Name FROM Account WHERE Industry = 'Technology'"

export_soql(sf, query, "tech_accounts.csv")

This will export all Account records with Industry = 'Technology' to the file `tech_accounts.csv`.

Page 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy