如何在SOQL中对同一对象进行内部或子查询



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

我正在将一个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__c的值,该值应该与外部查询中的DATA1__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子句。

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

尝试以下

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;
    }
}

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)

相关内容

  • 没有找到相关文章

最新更新