Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- General Development
- :
- What SOQL does salesforce.com use to execute a rep...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
What SOQL does salesforce .com use to execute a report?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 09:24 AM
Hi all:
I'm a relative newb. I'm building an integration with salesforce.com via the SOAP API. I've reached a sticking point. There is a report that I need to access via the API. I understand I can't access this directly, but the preferred approach is to mimic the SOQL that the report would be running, and generate the same data set that way.
This seems straight forward, but I can't seem to make my SOQL get the same number of results as the report in salesforce.com. Attached is a screen capture from the report page, as well as the SOQL I'm trying to use to generate the same data set.

SELECT Count(Id), (SELECT Contact.Name FROM Account.Contacts WHERE Contact.MaRS_Contact_Relationship__c INCLUDES ('Advisory Services Primary Contact') AND Contact.Inactive_Person_left_company__c = false) FROM Account WHERE MaRS_Company_Relationships__c INCLUDES ('Active VG Client', 'High Potential Client', 'SiG Client')
Can anyone see how these differ? Or do you know how, in general, to get the SOQL that the report is executing?
Solved! Go to Solution.
Re: What SOQL does salesforce .com use to execute a report?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 10:35 AM
The only thing I can think of is the outer query is only filtering on the account. Try doing it from the child object...
SELECT Count(Id),Name FROM Contact WHERE Account.MaRS_Company_Relationships__c INCLUDES ('Active VG Client', 'High Potential Client', 'SiG Client') AND MaRS_Contact_Relationship__c INCLUDES ('Advisory Services Primary Contact') AND Inactive_Person_left_company__c = false GROUP BY Name
Certified Salesforce Developer
Check out my blog. http://andrewwilkinsonsf.blogspot.com/
Re: What SOQL does salesforce .com use to execute a report?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 10:47 AM
If it makes you feel better, reports aren't run in SOQL. They get translated directly into SQL in the underlying database, so they can sometimes do things you can't do in SOQL.
Re: What SOQL does salesforce .com use to execute a report?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 11:19 AM
Thanks so much for taking the time to respond!
I tried this, but it still doesn't get me to the magic number of records. When running the report in Salesforce it finds 1,204 records. When running my previous report I get 1,555. This was a good idea, but running this gets me 1,062 records, so this isn't getting it either. I'm stumped.
Re: What SOQL does salesforce .com use to execute a report?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 12:20 PM
Oh. Actually, no. That looks like it was exactly it Andrew. The continuing discrepency was due to a difference between my prod and sandbox instances.
Although I think I understand it, can you expand on "the outer query is only filtering on the account" Do you mean that in the first query I may have been getting "extra" Account objects that don't have child "Contacts" and that's what made the difference?
Exactly.
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 12:24 PM - edited 12-07-2012 12:25 PM
Exactly. THE sub query was returning no results but the outer query was still returning the accounts whether or not they had contacts matching the criteria.
Certified Salesforce Developer
Check out my blog. http://andrewwilkinsonsf.blogspot.com/
Re: Exactly.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 12:27 PM
Ah ha! Ok. Then my query is exactly what is wanted, and my collaborator's report is incorrect :)
Thanks so much for your help!
Re: Exactly.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 12:49 PM
No problem. If you mark the post that has the query in it for everyones benefit that would be great.
Certified Salesforce Developer
Check out my blog. http://andrewwilkinsonsf.blogspot.com/

