22
33import json
44import logging
5+ import re
56from pathlib import Path
67from typing import Optional
78
@@ -129,13 +130,15 @@ def get_first_benchmark(self) -> dict:
129130 else :
130131 raise Exception ("Failed to return a Benchmark" )
131132
132- def get_benchmark_by_custom_id (self , salesforce_benchmark_id : str ) -> dict :
133- """Return the benchmark by the Salesforce Benchmark ID.
133+ def get_benchmark_by_custom_id (self , custom_id_name : str , custom_id_value : str ) -> dict :
134+ """Return the benchmark by the custom Salesforce Benchmark ID.
134135
135136 Args:
136- salesforce_benchmark_id (str): Salesforce Benchmark ID of the property to return
137- Note: this is not necessarily the Benchmark ID (it's a separate field)
138- # TODO: make this configurable?
137+ custom_id_name (str): Name of the custom ID field
138+ custom_id_value (str): Value of the custom ID field
139+ Note: this is not necessarily the Benchmark ID (it's a separate field that should be unique
140+ and serves as the "key" for retrieving the benchmark, but it is not necessarily the actual
141+ record ID in Salesforce)
139142
140143 Returns:
141144 dict: OrderedDict([('attributes',
@@ -145,18 +148,23 @@ def get_benchmark_by_custom_id(self, salesforce_benchmark_id: str) -> dict:
145148 ...
146149 """
147150
151+ # Validate field name to prevent SQL injection
152+ # Field names in Salesforce should only contain alphanumeric characters, underscores, and end with __c for custom fields
153+ if not re .match (r"^[a-zA-Z_][a-zA-Z0-9_]*(__c)?$" , custom_id_name ):
154+ raise ValueError (f"Invalid field name: { custom_id_name } " )
155+
148156 benchmark_exist = self .connection .query (
149- format_soql ("Select Id from Benchmark__c where Salesforce_Benchmark_ID__c = {} " , salesforce_benchmark_id ),
157+ format_soql (f "Select Id from Benchmark__c where { custom_id_name } = {{}} " , custom_id_value ), # noqa: S608
150158 )
151159 if len (benchmark_exist ["records" ]) == 1 :
152160 # if there is a single record, then it exist, but
153161 # we need to get the entire record for the request
154162 rec = self .get_benchmark_by_id (benchmark_exist ["records" ][0 ]["Id" ])
155163 return rec
156164 elif len (benchmark_exist ["records" ]) > 1 :
157- # there are multiple properties with the same name , raise error
165+ # there are multiple properties with the same custom ID , raise error
158166 raise Exception (
159- f"Failed to return Benchmark { salesforce_benchmark_id } ...multiple benchmarks with that name found" ,
167+ f"Failed to return Benchmark { custom_id_value } ...multiple benchmarks with that custom ID found" ,
160168 )
161169 else :
162170 # there is no property, return empty dict
@@ -307,6 +315,26 @@ def get_property_by_id(self, property_id: str) -> dict:
307315 except BaseException :
308316 raise Exception ("Error retrieving property by ID" )
309317
318+ def get_accounts (self ) -> list :
319+ """Get all accounts in salesforce
320+
321+ Returns:
322+ list: list of accounts in salesforce
323+ """
324+ soql_query = "SELECT Id, Name FROM Account"
325+ results = self .connection .query_all (soql_query )
326+ return results ["records" ]
327+
328+ def get_contacts (self ) -> list :
329+ """Get all contacts in salesforce
330+
331+ Returns:
332+ list: list of contacts in salesforce
333+ """
334+ soql_query = "SELECT Id, Name, Email FROM Contact"
335+ results = self .connection .query_all (soql_query )
336+ return results ["records" ]
337+
310338 def get_account_by_account_id (self , account_id : str ) -> dict :
311339 """Return the account by the account ID.
312340
0 commit comments