+ Start a Discussion
Matt Nelson 4Matt Nelson 4 

Apex DataLoader returns different records than API Query() call

Hi everyone,
Hoping someone can help shed some light - I'm getting different record counts from the Apex DataLoader than from the Explorer SOQL tester or our API calls.
We're trying to replicate data down from a Salesforce instance using the partner API.
The application we've built logs in under the API account we've set up, then issues a Query request against the Salesforce instance. Here's the query we're sending:

SELECT Id, Subject, AccountId, OwnerId, Type, CreatedDate, RecurrenceActivityId, RecurrenceStartDateTime, RecurrenceType, Call_Result__c, Case_Safe_ID__c, Event_Status__c, Task_Sub_Type__c, Task_Type__c FROM Event

This call returns 2 records sucessfully, and the QueryResult's done property is true.
I copy the same query and run it in the Apex Explorer SOQL tool, which returns the same 2 records.
I open the Apex DataLoader, log in with the same account, choose export, then use the same SOQL query to define the export. The DataLoader exports 8 records instead of 2.
I've checked to see whether the 6 extra records are deleted, archived, private, or in some different status than the two that are returned, but they're not. If I copy the IDs for the extra records, I can browse to them in Salesforce, so they seem to be real records. I've tried QueryAll in Explorer, but it still only returns 2 records.

1. Does anyone have any ideas on why there would be differences based on which tool I'm using? I was under the impression that everything should be the same as long as I'm using the same login credentials.
2. Does anyone have any recommendations on what changes I might need to make to the Query() call in order to get all 8 records?
 
Best Answer chosen by Matt Nelson 4
StephenKennyStephenKenny
Hmm very strange indeed. Can you check the api version of yoru code if this is stored in a class? I recall reading somewhere that older api versions dont return all records when new activites are related to multiple objects. If this is the case, change the api version up to the latest to see if that works.

Failing that, I am not sure what the issue could be unfortunatly. If you do manage to solve it, could you post the solution here as I would be interested to know.

Regards
Stephen

All Answers

StephenKennyStephenKenny
HI Matt,

I suspect the additional 6 records are 'Recurring Events' which are technically still events, however they are treated slightly differently. You may need to modify your API query or dataloader to exclude / include events where the isRecurring field is true.

Please remeber to mark this thread as solved with the answer that best helps you.

Kind Regards
Stephen
Matt Nelson 4Matt Nelson 4
Thanks Stephen. I just checked the records coming back from the DataLoader, and all of them have ISRECCURRENCE = false and RECURRENCEACTIVITYID is empty. Does that rule out recurrence as the cause?
Matt Nelson 4Matt Nelson 4
As an update, I've also found the same difference between in the Force.com explorer and the QueryEditor built in to Salesforce. We've also found that the QlikView Salesforce extension pulls in the full set of records. So to recap:

These tools show the correct counts:
  • Query editor inside of Salesforce developer console
  • Apex DataLoader
  • QlikView Salesforce extension
These tools only show a subset of the records:
  • Force.com Explorer
  • Our custom API integration engine
I'm using the same login information for all five tools.
I'm starting to wonder if the difference might be between using the Partner API and the Bulk API or Enterprise API. Is anyone familiar with which API the above tools are using? I tried using Fiddler to intercept the calls out of Apex DataLoader and figure out what's different, but it turned out not to be trivial to catch that traffic on my machine.
StephenKennyStephenKenny
Hi Matt,

I have just realised that the missing records are probably archived, which is why they do not appear in some queries. Salesforce automatically archives activities after 1 year - you can contact them to chnage this to 2 or 3 years.

To display archived activities in a query, you need to add the 'ALL ROWS' to the end of your query. See the link below for the official line on this:
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_query_all_rows.htm

So your origianal query above should look like this:
SELECT Id, Subject, AccountId, OwnerId, Type, CreatedDate, RecurrenceActivityId, RecurrenceStartDateTime, RecurrenceType, Call_Result__c, Case_Safe_ID__c, Event_Status__c, Task_Sub_Type__c, Task_Type__c FROM Event ALL ROWS

Regards
Stephen
Matt Nelson 4Matt Nelson 4
Hi Stephen,

Thank you for the suggestion. Unfortunately, that didn't solve the problem. The activities in question happened earlier this month. Regardless, I would expect the Query Editor to return the same results as the Force.com explorer or a custom call to the API, but I'm still getting differences. Any ideas on what else might be the problem? I've checked the deleted flags, archived flags, differences in accounts, dates, statuses, but so far I can't see anything consistently different between the rows that are returned and those that aren't.

I've checked some other objects and so far it looks like only Tasks and Events are affected by this problem. Any other ideas on what I might look at?

Thanks for the help!

-Matt
StephenKennyStephenKenny
Hmm very strange indeed. Can you check the api version of yoru code if this is stored in a class? I recall reading somewhere that older api versions dont return all records when new activites are related to multiple objects. If this is the case, change the api version up to the latest to see if that works.

Failing that, I am not sure what the issue could be unfortunatly. If you do manage to solve it, could you post the solution here as I would be interested to know.

Regards
Stephen
This was selected as the best answer
Matt Nelson 4Matt Nelson 4
Stephen,

I can't thank you enough for this. I should have thought to check the version. We were on version 20. I just updated to version 33 and the activities are showing up now! Maybe this means that whoever is maintaining the Force.com Explorer needs to update their API reference as well.

Many thanks!

-Matt