Salesforce apex:从列表中查询

Salesforce apex:从列表中查询,salesforce,apex-code,apex,Salesforce,Apex Code,Apex,我用的是apex和salesforce的东西。我有一些帐户的列表,现在我需要创建另一个有效的帐户列表。想象一下这是一个列表: List<Account__c> accounts = [Select Name, Status From Account__c]; . . . // now I need a new list with all the accounts that the status == 'valid' //this is not working List

我用的是apex和salesforce的东西。我有一些帐户的列表,现在我需要创建另一个有效的帐户列表。想象一下这是一个列表:

 List<Account__c> accounts = [Select Name, Status From Account__c];
 .
 .
 .
 // now I need a new list with all the accounts that the status == 'valid'

 //this is not working
 List<Account__c> accounts = [Select Name, Status From :accounts
                              where status == 'valid'];

是否有办法获取列表?

请检查以下查询:

列出帐户=[从帐户中选择名称、状态]; . . . //现在,您需要一个新列表,其中包含状态为“valid”的所有帐户

列表帐户=[从帐户中选择名称、状态 其中status='valid'和id IN:accounts]

试试这个:

List<Account__c> accounts = [Select Id, Name, Status From Account__c];
List<Account__c> otherAccounts = [Select Name, Status From Account__c where Id IN :accounts AND status = 'valid'];
问题的答案如下: