Salesforce Apex,SOQL,将数据库中的结果添加到列表中,错误
我想将数据库中的结果添加到列表中。但是有一个bugSalesforce Apex,SOQL,将数据库中的结果添加到列表中,错误,salesforce,apex,soql,Salesforce,Apex,Soql,我想将数据库中的结果添加到列表中。但是有一个bug String str = '\'AOC\',\'BPD\',\'CRE\''; List<String> lstString = str.split(','); List<Shop_Product__c> productList = new List<Shop_Product__c>(); Integer i = 0; for (String record: lstString) { System.d
String str = '\'AOC\',\'BPD\',\'CRE\'';
List<String> lstString = str.split(',');
List<Shop_Product__c> productList = new List<Shop_Product__c>();
Integer i = 0;
for (String record: lstString) {
System.debug('record[' + i + ']: ' + record);
if ((record != null) && (productList != null)) {
productList.add([SELECT Id, Brand__c
FROM Shop_Product__c
WHERE Brand__c = :record
LIMIT 10]);
System.debug('productList[' + i + ']: ' + productList);
System.debug('Here in for ----------------------------------------');
}
++i;
}
String str='AOC\'、'BPD\'、'CRE\';
List lstString=str.split(',');
List productList=新列表();
整数i=0;
for(字符串记录:lstString){
系统调试('record['+i+']:'+record);
如果((记录!=null)&&(产品列表!=null)){
productList.add([选择Id,品牌]
来自商店\产品\ c
其中Brand_uuc=:记录
限额(10);;
调试('productList['+i+']:'+productList);
System.debug('herein for-------------------------------------------------------);
}
++一,;
}
错误为System.QueryException:List没有可分配给SObject的行。
这是解释,但我不明白我应该怎么做。这个
列表
方法add()
只接受一个sObject。这就是为什么会出现QueryException
,就像链接到的示例一样
您可以使用addAll()
方法创建列表
上下文,如果没有响应记录,则可以避免异常。使用addAll()方法,则不会出现错误。谢谢