function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lars NielsenLars Nielsen 

Anybody seen any issues SOAP method getDeleted() not respecting date ranges

Long story short I was testing this a few weeks ago and no matter what date ranges we put in it ALWAYS brought back everything in the recycle bin. 
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_getdeleted.htm?search_text=getdeleted

GetDeletedResult = connection.getDeleted(string sObjectType, dateTime startDate, dateTime EndDate);

 
Daniel BallingerDaniel Ballinger
I just ran a quick test to try and relicate the problem. 
To do so I deleted 4 Account records over a period of a couple of minutes.

Then ran the following code in .NET. 
 
SalesforceSession session = //... Create a Session to the Org with deleted Accounts

            //DateTime startDate = DateTime.Today.AddDays(-5).Date.ToUniversalTime();
            // UTC DateTime that is greater than the first of the 4 records deleted.
            DateTime startDate = DateTime.Parse("22/02/2016 9:35:00 p.m.");
            
            DateTime endDate = DateTime.Today.AddDays(1).Date.ToUniversalTime();

            GetDeletedResult deletedAccounts = session.Binding.getDeleted(Account.SFType, startDate, endDate);
            System.Diagnostics.Debug.WriteLine("earliestDateAvailable: " + deletedAccounts.earliestDateAvailable + " latestDateCovered:" + deletedAccounts.latestDateCovered);

            //Assert.IsTrue(startDate <= deletedAccounts.earliestDateAvailable);
            Assert.IsTrue(deletedAccounts.latestDateCovered <= endDate);

            foreach (DeletedRecord dr in deletedAccounts.deletedRecords)
            {
                System.Diagnostics.Debug.WriteLine(dr.id + " deletedDate:" +  dr.deletedDate);
                Assert.IsTrue(startDate <= dr.deletedDate);
                Assert.IsTrue(dr.deletedDate <= endDate);
            }

I found that this brought back only the expected 3 records. The 4th record, with the UTC Deletion Date of 22/02/2016 9:34:13 p.m. was not returned. If I altered the startDate to be 5 days ago I get all 4 records back.

One oddity I did was was the earliestDateAvailable came back as 6/01/2016 6:49:00 p.m. UTC, which doesn't seem to line up with the documentation (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_getdeleted_getdeletedresult.htm):
 
For the object type of the getDeleted() call, the timestamp (Coordinated Universal Time (UTC)—not local— timezone) of the last physically deleted object. If this value is less than endDate, the call will fail, and you should resynch your data before performing another replication.

The value was clearly less than my endDate of 23/02/2016 11:00:00 a.m. (UTC). So I'm not sure what is going on there.

Dates for all the returned records. The first was successfully omitted based on moving the startDate param.

00190000009JUneAAG deletedDate:22/02/2016 9:34:56 p.m.
00190000009JUn0AAG deletedDate:22/02/2016 9:35:04 p.m.
00190000009JUnjAAG deletedDate:22/02/2016 9:35:14 p.m.
00190000009JUn5AAG deletedDate:22/02/2016 9:35:21 p.m.