[SalesForce] How to get the information of a user who deleted an object

Salesforce REST API supports the getdeleted endpoints to furnish a list of deleted records for an SObject. The response from the API looks like this

{ 
"deletedRecords" : 
[ 
    { 
        "id" : "a00D0000008pQRAIA2", 
        "deletedDate" : "2013-05-07T22:07:19.000+0000"
    }
],
"earliestDateAvailable" : "2013-05-03T15:57:00.000+0000",
"latestDateCovered" : "2013-05-08T21:20:00.000+0000"
}

The problem is that this response does not contain any information about the user who performed the delete. How to get the Id of the user who performed this operation?

We cannot make an API call on the respective SObject Id(to get LastModifiedBy) as it has been deleted and will not appear in the normal API call. What is the solution?

One way could be to use the queryall() functionality of the SOAP API. How can this be done using the REST API? Even if this approach works, it will only work for records that have moved to the recycle-bin after the delete i.e a soft delete. What about the records that have been hard deleted directly?

As an observation, if you go to the recycle-bin it shows the Deleted By and Deleted Date on the deleted records. How does Salesforce show that information because SObjects dont seem to have fields for deleted-by and deleted-date. If there is, how can it be used to solve this problem?

Best Answer

Use the REST API's QueryAll, rather than plain Query. You can even follow the LastModifiedBy relation to drill down into user fields:

$ curl -H 'X-PrettyPrint: 1' -H 'Authorization: Bearer ACCESS_TOKEN' \
https://na1.salesforce.com/services/data/v31.0/queryAll/?q=SELECT+Id,Name,LastModifiedById,LastModifiedBy.Name,LastModifiedDate+FROM+Account+WHERE+isDeleted+=+TRUE
{
  "totalSize" : 1,
  "done" : true,
  "records" : [ {
    "attributes" : {
      "type" : "Account",
      "url" : "/services/data/v31.0/sobjects/Account/001E000000ugw6hIAA"
    },
    "Id" : "001E000000ugw6hIAA",
    "Name" : "DeletedMe",
    "LastModifiedById" : "005E0000000HiFiIAK",
    "LastModifiedBy" : {
      "attributes" : {
        "type" : "User",
        "url" : "/services/data/v31.0/sobjects/User/005E0000000HiFiIAK"
      },
      "Name" : "Pat Patterson"
      "Profile" : {
        "attributes" : {
          "type" : "Profile",
          "url" : "/services/data/v31.0/sobjects/Profile/00eE0000000V6fYIAS"
        },
        "Name" : "System Administrator"
      }
    },
    "LastModifiedDate" : "2014-05-30T21:39:30.000+0000"
  }]
}