Beatbox: How do I add OR function to WHERE clause when pulling data from SFDC?

爱⌒轻易说出口 提交于 2020-01-06 15:18:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!