Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions tools/soql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
session_manager = SalesforceSessionManager(username, password_with_token, login_url, self.session.storage)

soql_query = tool_parameters.get("soql_query", "").strip()
include_archived = tool_parameters.get("include_archived", False)
logger.info(f"SOQL query to execute: {soql_query[:100]}{'...' if len(soql_query) > 100 else ''}")
logger.info(f"Include archived records: {include_archived}")

if not soql_query:
logger.error("SOQL query is empty")
Expand All @@ -48,8 +50,10 @@ def make_api_call(session_id: str, instance_url: str) -> requests.Response:
}

encoded_query = urllib.parse.quote(soql_query)
url = f"{instance_url}/services/data/v63.0/query?q={encoded_query}"
logger.info(f"Making Salesforce API call to: {instance_url}/services/data/v63.0/query")
# Use queryAll endpoint for archived records, standard query endpoint otherwise
endpoint = "queryAll" if include_archived else "query"
url = f"{instance_url}/services/data/v63.0/{endpoint}?q={encoded_query}"
logger.info(f"Making Salesforce API call to: {instance_url}/services/data/v63.0/{endpoint}")
return requests.get(url, headers=headers, timeout=30)

try:
Expand Down Expand Up @@ -87,15 +91,18 @@ def make_api_call(session_id: str, instance_url: str) -> requests.Response:
"totalSize": result_data.get("totalSize", 0),
"done": result_data.get("done", True),
"records": result_data.get("records", []),
"query": soql_query
"query": soql_query,
"includeArchived": include_archived
}

if formatted_result["totalSize"] > 0:
summary = f"Query executed successfully. Found {formatted_result['totalSize']} record(s)."
logger.info(f"SOQL query completed successfully, found {formatted_result['totalSize']} records")
archive_info = " (including archived records)" if include_archived else ""
summary = f"Query executed successfully. Found {formatted_result['totalSize']} record(s){archive_info}."
logger.info(f"SOQL query completed successfully, found {formatted_result['totalSize']} records{archive_info}")
else:
summary = "Query executed successfully. No records found."
logger.info("SOQL query completed successfully, no records found")
archive_info = " (including archived records)" if include_archived else ""
summary = f"Query executed successfully. No records found{archive_info}."
logger.info(f"SOQL query completed successfully, no records found{archive_info}")

yield self.create_text_message(summary)
yield self.create_json_message(formatted_result)
Expand Down
17 changes: 17 additions & 0 deletions tools/soql_query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ parameters:
pt_BR: A consulta para executar no Salesforce. Deve usar sintaxe SOQL válida.
llm_description: The SOQL query string to execute against Salesforce. Must use valid SOQL syntax. Example queries - SELECT Id, Name FROM Account LIMIT 10; SELECT Id, Email FROM Contact WHERE Name = 'John Doe'; SELECT Id, Channel_Type__c FROM Holistic_Engagement__c WHERE Person__r.Contact__r.Name = 'John Doe' LIMIT 10
form: llm
- name: include_archived
type: boolean
required: false
default: false
label:
en_US: Include Archived Records
zh_Hans: 包含已归档记录
pt_BR: Incluir Registros Arquivados
human_description:
en_US: Whether to include archived/deleted records in the query results. When enabled, uses queryAll endpoint to retrieve all records including archived ones.
zh_Hans: 是否在查询结果中包含已归档/已删除的记录。启用时,使用 queryAll 端点检索包括已归档记录在内的所有记录。
pt_BR: Se deve incluir registros arquivados/excluídos nos resultados da consulta. Quando habilitado, usa o endpoint queryAll para recuperar todos os registros, incluindo os arquivados.
llm_description: Set to true to include archived and deleted records in the query results. This uses Salesforce's queryAll endpoint instead of the standard query endpoint. Useful for retrieving historical data or archived records.
form: form
extra:
python:
source: tools/soql_query.py
Expand All @@ -43,3 +57,6 @@ output_schema:
query:
type: string
description: The original SOQL query that was executed
includeArchived:
type: boolean
description: Whether archived records were included in the query results