2

我面临从同一个对象中选择值的问题。我在下面提供了查询。

我正在将 Java J2EE 应用程序迁移到 Salesforce,以下查询在我的SQL.
我正在尝试在 中做同样的事情SOQL,但它不起作用。

 SELECT DATA1__c, TEXT__c 
     FROM PARAMETERS__c 
     WHERE ( (TYPE__c = 'ADMINISTRATEUR') 
         AND (KEY1__c LIKE 'MONTAGE%') (AND KEY2__c = '')) 
         AND (DATA1__c 
                  IN (SELECT KEY1__c 
                      FROM Parameters__c 
                      WHERE TYPE__c = 'PERE_TECHNIQUE'))

在上面的查询中,我需要从外部查询中获取应该匹配TYPE的值。'TECHNIQUE' where KEY1__cDATA1__c

查询与此示例非常相似

 SELECT Id 
     FROM Idea 
     WHERE ((Idea.Title LIKE 'Vacation%') 
         AND (CreatedDate > YESTERDAY)  
         AND (Id IN (SELECT ParentId 
                     FROM Vote 
                     WHERE CreatedById = '005x0000000sMgYAAU'))

唯一的区别是该IN子句与不同的对象一起使用。在我的查询中,我尝试使用IN来自相同对象参数的子句。

如果有任何进一步的澄清,请告诉我。

4

2 回答 2

1

Vote Id和Idea Id不一致,Vote内选返回列表,子查询没有结果Id IN (SELECT ParentId FROM Vote....

将代码更改为

set<Id> ideaIdSet = new set<Id>();
for(Vote vote : [SELECT ParentId FROM Vote WHERE CreatedById = '005x0000000sMgYAAU']){
    ideaIdSet.add(vote.ParentId);
} 

SELECT Id 
     FROM Idea 
     WHERE ((Title LIKE 'Vacation%') 
         AND (CreatedDate > YESTERDAY)  
         AND (Id IN ideaIdSet)
于 2013-07-28T05:35:11.307 回答
1

尝试以下

List<String> pereTechniqueParams = new List<String>();
for (String key: 
          [SELECT KEY1__c FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']) {
    pereTechniqueParams.add(key.KEY1__c);
}

List<Parameters__c> params = [SELECT DATA1__c, TEXT__c 
                                  FROM PARAMETERS__c 
                                  WHERE (TYPE__c = 'ADMINISTRATEUR' 
                                         AND KEY1__c LIKE 'MONTAGE%' 
                                         AND KEY2__c = '') 
                                      AND DATA1__c IN:pereTechniqueParams];

更新:

for (Parameters__c key1 : [SELECT KEY1__c 
                    FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']) {
    pereTechniqueParams.add(key1.KEY1__c);
} 

不要使用字符串使用参数__c

public class LookUpController {
    public List<Parameters__c> getParamters() {
        List<String> pereTechniqueParams = new List<String>();
        for (Parameters__c key1 : [SELECT KEY1__c 
                            FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']) {
            pereTechniqueParams.add(key1.KEY1__c);
        } 
        List<Parameters__c> params = [SELECT DATA1__c, TEXT__c 
                               FROM PARAMETERS__c 
                               WHERE TYPE__c = 'ADMINISTRATEUR' 
                                   AND KEY1__c LIKE 'MONTAGE%' 
                                   AND KEY2__c = '' 
                                   AND Data1__c IN: pereTechniqueParams];
        return params;
    }
}
于 2013-07-28T11:59:17.307 回答