0

How can i combine this two request in salesforce SOQL query into 1 single request in iOS:

NSString *theRequest = [NSString stringWithFormat:@"SELECT Name, OpportunityID FROM OpportunityLineItem where OpportunityID = '%@'", [companyDic objectForKey:@"Id"]];
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:theRequest];
[[SFRestAPI sharedInstance] send:request delegate:self];

and

NSString *theRequest2 = [NSString stringWithFormat:@"SELECT CompetitorName FROM OpportunityCompetitor where OpportunityID = '%@'", [companyDic objectForKey:@"Id"]];
SFRestRequest *request2 = [[SFRestAPI sharedInstance] requestForQuery:theRequest2];
[[SFRestAPI sharedInstance] send:request2 delegate:self];
Aldrin Equila
  • 165
  • 2
  • 17

1 Answers1

0

Use this subquery:

SELECT Name, OpportunityID FROM OpportunityLineItem where OpportunityID IN (SELECT OpportunityID FROM OpportunityCompetitor where OpportunityID = '%@')

Kampai
  • 22,848
  • 21
  • 95
  • 95
  • ERROR|SFNetworkOperation|callDelegateDidFailWithError The left operand field in the where expression for outer query should be an id field which matches the select, cannot use: 'OpportunityID' – Aldrin Equila Oct 17 '14 at 09:47
  • @AldrinEquila: I have cross checked with my database, It should be work perfectly. – Kampai Oct 17 '14 at 09:59
  • Can you please show me how you use that subquery with code? – Kampai Oct 17 '14 at 10:18
  • NSString *theRequest = [NSString stringWithFormat:@"SELECT Name, OpportunityID FROM OpportunityLineItem where OpportunityID IN (SELECT CompetitorName FROM OpportunityCompetitor where OpportunityID = '%@')", [companyDic objectForKey:@"Id"]]; SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:theRequest]; [[SFRestAPI sharedInstance] send:request delegate:self]; – Aldrin Equila Oct 17 '14 at 10:31
  • @AldrinEquila - Check that `IN (SELECT `. It should be `OpportunityID`. That's why its giving you an error. Here from inner query you are returning `CompetitorName` and from outer query you are comparing with `OpportunityID` is wrong. Operand from both side should be same. – Kampai Oct 17 '14 at 10:34
  • 1
    The query is suppose to be like this: `[NSString stringWithFormat:@"SELECT Name, OpportunityID FROM OpportunityLineItem where OpportunityID IN (SELECT OpportunityID FROM OpportunityCompetitor where OpportunityID = '%@')", [companyDic objectForKey:@"Id"]]` – Kampai Oct 17 '14 at 10:36
  • its working now. but it doesn't show the product name anymore. i want to display the competitorName and product name – Aldrin Equila Oct 17 '14 at 10:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63217/discussion-between-kampai-and-aldrin-equila). – Kampai Oct 17 '14 at 10:48