I ‘d like to add that as you can see I'm using .GetInstances method of AFNotificationList class object. Is it possible to get history records using some other approach? Maybe if I used some other way, I would be able to get number of records and retrieve records by id number or somehow else.
I am not aware of any ways to find a count of the total number of history record since the notification is created, or for a specific time range. So I can't suggest much in terms of how you can do it better, or how you can find the count without searching for the notification history first.
In the comments of your code snippet, you mentioned that you are getting all history record from the notification. In addition, your search condition in FindNotifications call is trying to find all defined notification as well. So essentially you are getting all history record for all notifications. I can see why it would take a long time to execute, if you have many notifications defined and also when there are a lot of events recorded in the history. May I ask what kind of analysis you are running that requires all the history record?
As for other methods for getting the notification instances, instead of ANNotificationList.GetInstances call which gets the notification instance for all notifications in the collection, there is also ANNotication.GetInstances call that get the instances for a specific notification
// Step1: when loading a bunch of objects, consider the "Load .. ( )" methods:
// Find notifications to load. As with all top-level objects, the
// notifications returned are only partially loaded into memory.
AFNamedCollectionList<AFNotification> notifications =
AFNotification.FindNotifications(myDB, "", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 100);
// The LoadNotifications call will fully load the notification into memory.
// The second parameter indicates whether the analysis should be loaded as well.
// For example, if you were going to display or edit analysis information, you would
// set this parameter to true.
Thank you for answers. I appreciate it. I'll try to use your advises.
Regarding "May I ask what kind of analysis you are running that requires all the history record?" - It's just common purpose application which allows to show notification history for noted time frame. Since we have 1-10k notifications, and each has pretty long history, in case user (even accidentally) selects 2-3 month period of time, it kills web service, that's why I'm trying to develop some algorithm to control number of retrieving data per one web service request, and of course I need to know all history records amount...
Maybe somebody has something else to add. Thank you again.