1

I need a list of all sobject records that got modified today. this is not just for one object but for all objects in the system. Is there a simpler way to do this?

3

Simpler way? well yes and no. We have Database.getUpdated method that returns Id of records updated in a particular time span.

It takes sObject Type , start date and end date as arguments and returns ID of updated record.

The tricky bit is not every object is supported, so you have add ignore list or some custom logic for objects not supported by getUpdatedMethod.

Map<String , List<Id>> updatedObject= new Map<String,List<Id>>();
Map<String, Schema.SObjectType> gd =
        Schema.getGlobalDescribe();

List<String> ignoreList = new List<String>();
ignoreList.add('feedattachment');
ignoreList.add('pushtopic');
ignoreList.add('apextestqueueitem');
ignoreList.add('objectpermissions');
ignoreList.add('fieldpermissions');
ignoreList.add('conversationentry');
ignoreList.add('permissionset');
ignoreList.add('oauthcustomscope');

for (String objectName : gd.keySet()) {

    if(!ignoreList.contains(objectName) && gd.get(objectName).getDescribe().Createable && gd.get(objectName).getDescribe().Updateable && !objectName.endsWith('share') && !objectName.startsWith('content') && !objectName.startsWith('collaboration')){
        Database.GetUpdatedResult updatedRecords = Database.getUpdated(objectName, System.now().addDays(-1), System.now());
        if (updatedRecords.getIds().size() > 0) {
            updatedObject.put(objectName, updatedRecords.getIds());
        }
    }


}

System.debug(updatedObject.keySet());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.