Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
最多允许2个半联接子选择(Salesforce)_Salesforce_Apex Code_Apex_Soql - Fatal编程技术网

最多允许2个半联接子选择(Salesforce)

最多允许2个半联接子选择(Salesforce),salesforce,apex-code,apex,soql,Salesforce,Apex Code,Apex,Soql,对于APEX Salesforce开发来说是相当新的,我发现其中一个SOQL语句存在问题 这是造成问题的代码。。我做了一些研究,发现我需要创建一组id,而不是对OpportunityId使用另一个select语句,然后在查询中引用它 String sumAvgQuery = 'SELECT StageName, COUNT(ID) opps, SUM(Amount) total, AVG(SVC_Svc0StageAge__c) Svc0, AVG(SVC_Svc1StageAge__c) Sv

对于APEX Salesforce开发来说是相当新的,我发现其中一个SOQL语句存在问题

这是造成问题的代码。。我做了一些研究,发现我需要创建一组id,而不是对OpportunityId使用另一个select语句,然后在查询中引用它

String sumAvgQuery = 'SELECT StageName, COUNT(ID) opps, SUM(Amount) total, AVG(SVC_Svc0StageAge__c) Svc0, AVG(SVC_Svc1StageAge__c) Svc1, ' +
                                'AVG(SVC_Svc2StageAge__c) Svc2, AVG(SVC_Svc3StageAge__c) Svc3, AVG(SVC_Svc4StageAge__c) Svc4, ' + 
                                'AVG(SVC_Svc5StageAge__c) Svc5, AVG(SVC_Svc6StageAge__c) Svc6, AVG(SVC_Svc7StageAge__c) Svc7, ' +
                                'AVG(SVC_Svc8StageAge__c) Svc8, AVG(SVC_Svc9StageAge__c) Svc9 ' +
                                'FROM Opportunity ' +
                                'WHERE StageName in (' + BTG_Utility.OPPORTUNITY_STAGES + ') ' +
                                'AND ID in (SELECT OpportunityId FROM OpportunityTeamMember WHERE UserId = \'' + String.escapeSingleQuotes(userId) + '\') ' +
                                ((cluster != null && cluster != '') ? 'AND SVC_AccountCluster__c = \'' + String.escapeSingleQuotes(cluster) + '\' ' : '') +
                                ((region != null && region != '') ? 'AND SVC_AccountRegion__c = \'' + String.escapeSingleQuotes(region) + '\' ' : '') +
                                ((country != null && country != '') ? 'AND CARE_AccountCountry__c = \'' + String.escapeSingleQuotes(country) + '\' ' : '') +                                                            
                                ((product != null && product != '') ? ' AND Id in (SELECT OpportunityId FROM OpportunityLineItem Where Product2.Name = \'' + String.escapeSingleQuotes(product) + '\' and Opportunity.IsClosed = FALSE) ' : '') +
                                'GROUP BY StageName)';

你能帮我做这个吗?非常感谢你的帮助

如果要使用类似Apex中的集合的集合,则需要首先填充集合,然后可以在SOQL查询中使用前面带有:的变量名

例如:

// First populate the Set with ID's using SOQL
set<Account> inputSet = new set<Account>([SELECT Id FROM Account LIMIT 5]);

//Alternatively manually populate the set
// set<String> inputSet = new set<String>();
// List<Account> accounts = new List<Account>([SELECT custom_id__c FROM Account LIMIT 5]);
// for (Account acc : accounts) {
//      inputSet.add(acc.custom_id__c);
// }
System.debug('inputSet: ' + inputSet);

// Use the set with the data 

List<Contact> contacts = [SELECT id FROM Contact where custom_id__c in :inputSet];
System.debug('contacts: ' + contacts);
希望有帮助

穆罕默德·伊姆兰