Apex获取帐户记录ID,列表中的联系名称(使用和条件)
在Salesforce中,我想检索其相关联系人名称必须在字符串列表中具有值的帐户。字符串列表为{'test','用户'}。我需要找到所有帐户,其中联系名称同时具有测试和用户为相关联系人,
我正在尝试下面尝试,但是下面的查询将显示一个帐户,其中甚至有1个值匹配为contact名称。
list< string>名称=新列表< string> {'test','用户'}; list< earcess>  =  nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;   nbsp; nbsp; nbsp; nbsp; nbsp; NBSP;&nbsp ;  (select select ofceptid  from nbsp; contacts  where firstName  like  like :names names;
请帮助
In Salesforce I would like to retrieve AccountIds where its related Contact FirstName must have values in list of String. List of string is {'Test','User'}. I would need to find all Accounts where Contact first Name has both Test and User as related Contacts,
I am trying as below but the below query will show accounts where even 1 value matches as Contact First Name.
List<String> names = new List<String>{'Test','User'}; List<Account> accountList = [ Select Id from Account Where Id IN (Select AccountId FROM Contacts where FirstName LIKE :names)];
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但这只能工作2次,您不能像这样写第三个“”(请参阅在这里)。
如果您需要一个更通用的解决方案,该解决方案可以获取任何大小的列表,您必须在循环中运行“我的”查询,一个2个名称,请将结果保存到某些
set&lt; id&gt;
或MAP ,使用mySet.RetainAll(IDSFROMCURRENTLOOPQUERY)
...当然在循环中查询的功能也有点邪恶。But it'll work only 2 times, you can't write 3rd "IN" like that (see here).
If you need a more generic solution that can take lists of any size you'd have to run "my" queries in loop, 2 names at a time, save results to some
Set<Id>
or Map, play with functions likemyset.retainAll(idsFromCurrentLoopQuery)
... Of course query in a loop is bit evil too.