0

All i want to do is to retrieve information from two standard objects Account and Case. For I have tried joins(which later I found does not work with SOQL), relationships (which does not exist in my case. except for default relationship). Following is another attempt using sub query: (By default relationship I mean that Id in Account is same as AccountId in Case)

Select Phone,City__c,CreatedDate,Name, (SELECT Customer_Satisfaction_Level__c,Product_Category__c FROM AccountId__r) FROM Account;

Also, SOQL does not allow aliases which would have helped me as I am working with QlikView. Please Help!

smartmeta
  • 1,149
  • 1
  • 17
  • 38
Salik
  • 508
  • 6
  • 17
  • 35

2 Answers2

0

Use This Below Query...Hope itz might be favourable for you

Select Phone,City__c,CreatedDate,Name, (SELECT Customer_Satisfaction_Level_c FROM AccountId_r where AccountId__r.ID=ID ) as Customer_Satisfaction_Level__c,(SELECT Product_Category_c FROM AccountId_r where AccountId__r.ID=ID ) as Product_Category__c FROM Account;

Aswin
  • 1
  • 2
  • nope.it does not work. AccountId__r was a relationship i thought existed but it does not. – Salik Nov 11 '13 at 07:45
0

You can select Accounts with related Cases like this:

List<Account> accounts = [Select Id, (Select Id From Cases) From Account];

And then iterate over results:

for (Account account : accounts) {
   for (Case case : account.Cases) {
      ...
   }
}
  • i want names from account and the case detail from cases. hence, a join between the two. – Salik Nov 12 '13 at 11:33
  • SELECT Id, Name, (SELECT Id, Name, some_field1, some_field2 FROM Cases) FROM Account. And in the loop instead of ... you can get this fields like this: SYSTEM.DEBUG('Account name - '+account.Name); SYSTEM.DEBUG('Related Case name - '+case.Name); – Dmitry Shnyrev Nov 15 '13 at 06:14