def get_all( self ): # TODO: A LIMIT must be added, or Bulk API should be used instead accounts = self._sf.query( "SELECT Id,AccountNumber,Name,CreatedDate,Website FROM Account") accounts = Parser.parse(accounts) return accounts
def get_by_id(self, contactId=None): """ Get SF contact :param contactId: contact ID :return: Account/False if contact was queried """ if contactId is not None: try: contact = self._sf.Contact.get(contactId) return Parser.parse(contact) except SalesforceResourceNotFound as e: # Not found print("[GET]{errorCode}: Resource {name} not found. {message}". format(message=e.content[0]['message'], name=e.resource_name, errorCode=e.content[0]['errorCode'])) return False except SalesforceMalformedRequest as e: # Field doesn't exist print( "[GET]{errorCode}: Malformed request {url}. {message} ID: {id}" .format(message=e.content[0]['message'], url=e.url, errorCode=e.content[0]['errorCode'], id=contactId)) return False except Exception as e: print("Something went wrong!") print(e) return False else: print("Contact ID is missing!") return False
def get_by_id(self, accountId=None): """ Get SF account :param accountId: ID string / list of IDs :return: JSON, JSON format list / False if account was not queried """ if accountId is not None: try: if isinstance(accountId, str): account = self._sf.Account.get(accountId) return [Parser.parse(account)] elif isinstance(accountId, list): accounts = [] for acc_id in accountId: account = self._sf.Account.get(acc_id) accounts.append(Parser.parse(account)) return accounts except SalesforceResourceNotFound as e: # Not found print("[GET]{errorCode}: Resource {name} not found. {message}". format(message=e.content[0]['message'], name=e.resource_name, errorCode=e.content[0]['errorCode'])) return False except SalesforceMalformedRequest as e: # Field doesn't exist print( "[GET]{errorCode}: Malformed request {url}. {message} ID: {accountId}" .format(message=e.content[0]['message'], url=e.url, errorCode=e.content[0]['errorCode'], accountId=accountId)) return False except Exception as e: print("Something went wrong!") print(e) return False else: print("Account ID is missing!") return False
def get_sobject(self, sobject=None, sobject_id=None): """Allows you to make a direct GET REST call if you know the path EXAMPLE: .get(path='sobjects/Account/0017j00000VLkZtAAL', params={"fields" : "Name"})) Arguments: * path: The path of the request Example: sobjects/User/ABC123/password' * params: dict of parameters to pass to the path * method: HTTP request method, default GET * other arguments supported by requests.request (e.g. json, timeout) :return JSON objects list / False if issue has occurred """ try: if isinstance(sobject_id, str): sobject_data = self.__getattr__(sobject).get(sobject_id) return [Parser.parse(sobject_data)] elif isinstance(sobject_id, list): sobjects_data = [] for sobject_sid in sobject_id: sobject_data = self.__getattr__(sobject).get(sobject_sid) sobjects_data.append(Parser.parse(sobject_data)) return sobjects_data except SalesforceResourceNotFound as e: print("[GET]{errorCode}: Resource {name} not found. {message}". format(message=e.content[0]['message'], name=e.resource_name, errorCode=e.content[0]['errorCode'])) return False except SalesforceMalformedRequest as e: # Deletion failed (could be due account being associated to existing cases) print( "[GET]{errorCode}: Malformed request {url}. {message}".format( message=e.content[0]['message'], url=e.url, errorCode=e.content[0]['errorCode'])) return False except Exception as e: print("Something went wrong!") print(e) return False
def get_opportunities(self, accountId=None): cases = self._sf.query( f"SELECT Id,Amount,IsClosed,IsWon,Type FROM Opportunity " f"WHERE AccountId='{accountId}'") return Parser.parse(cases)
def get_cases(self, contactId=None): cases = self._sf.query( f"SELECT Id,CaseNumber,ContactId,AccountId FROM Case WHERE ContactId='{contactId}'" ) return Parser.parse(cases)
def get_account_contacts(self, accountId=None): contacts = self._sf.query( f"SELECT Id,FirstName,LastName,Email,Phone,AccountId FROM Contact WHERE AccountId='{accountId}'" ) return Parser.parse(contacts)
def get_account_contracts(self, accountId=None): contracts = self._sf.query( f"SELECT Id,ContractNumber,ContractTerm,CreatedById,CreatedDate,Description,OwnerId,AccountId FROM Contract WHERE AccountId='{accountId}'" ) return Parser.parse(contracts)
def get_cases(self, accountId=None): cases = self._sf.query( f"SELECT Id,CaseNumber,ContactId,AccountId,Type,Status,Subject,Description FROM Case " f"WHERE AccountId='{accountId}'") return Parser.parse(cases)
def get_by_name(self, name): accounts = self._sf.query( "SELECT Id,AccountNumber,Name,CreatedDate,Website FROM Account WHERE Name='{name}'" .format(name=name)) return Parser.parse(accounts) # Returns list of accounts
def get_by_domain(self, website): accounts = self._sf.query( "SELECT Id,AccountNumber,Name,CreatedDate,Website FROM Account WHERE Website='{website}'" .format(website=website)) return Parser.parse(accounts)
def get_all_where(self, where_query=None): accounts = self._sf.query( "SELECT Id,AccountNumber,Name,CreatedDate,Website FROM Account WHERE {0}" .format(where_query)) return Parser.parse_to_object(accounts)