问题
Currently I am querying data from the Account object for only accounts with Opportunities. However, I want to add an OR function so that it will query data for accounts that have Contacts as well.
What is the syntax for adding an OR to that? As in (SELECT AccountID FROM Opportunity OR Contact). So if the AccountID is in either set of data, it will pull the website for me.
Current State:
query_result = svc.query("SELECT ID,Website FROM Account where ID in (SELECT accountId FROM Opportunity)")
回答1:
You can follow the link below
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_conditionexpression.htm
回答2:
This is a restriction of SOQL Comparison Operators - Semi-Joins with IN ... that
- You cannot use subqueries with OR.
You can get an error message
MALFORMED_QUERY Semi join sub-selects are not allowed with the 'OR' operator
even if you combine WHERE Id IN (SELECT ...) OR ...
with any trivial condition. There is no solution by SOQL, but there are two complicated workarounds: A) Create two roll-up summary fields with count of Opportunities and count of Contacts to can combine them without semi-join or B) combine the results of two queries by Python.
来源:https://stackoverflow.com/questions/30902100/beatbox-how-do-i-add-or-function-to-where-clause-when-pulling-data-from-sfdc