1

The object which has the history tracking enabled in my organization is being modified 3 to 4 times a day, so we end up with 112 history records per month.

I have a page that queries the history and compares the values in the dates, and the page times out when executing the code because the query takes too long to run. If I run the query on the console, it takes too long too (here "too long" means, sometimes, some minutes). The interesting thing is that when the server can get me the results, the query becomes faster.

It seems that the records are not in memory, and then Salesforce gets the history on memory to make it faster to query the records (and that's why it is faster sometime after).

Has anyone experienced this situation before? If so, how did you solve this issue?

  • It's all about data volume, I expect. I would think it might be faster for a rarely edited object. – Adrian Larson Feb 17 '17 at 18:52
  • 1
    Suggest you input the query you are using to the Query Plan Tool and see if it reports anything you can improve on. – Keith C Feb 17 '17 at 19:14
  • @AdrianLarson at first I thought it was about data volume too. But then I tried querying the last 10 records on the table, for example, and it would take some time too (and I was expecting that it would take less than a few seconds). – Renato Oliveira Feb 18 '17 at 0:23
  • @KeithC thanks for the suggestion. But the only things I can improve at this moment are the specific time frame the records were created. If I limit the records for a specific week, for example, then it would still take some time. I will check this out, but it seems that I will have to change my approach to my issue. Maybe storing the value I need in some record. – Renato Oliveira Feb 18 '17 at 0:24
  • @RenatoOliveira Did it help to query data for a shorter amount of time? – Arturo Hernandez Aug 23 '18 at 21:17
2

Like any database table, queries can become increasingly slower when a lot of entries are placed into the table. You can help alleviate this problem by setting up a History Retention Policy to limit how far back your records go. Once the retention period is met, those entries move from the FieldHistory table to the FieldHistoryArchive table to keep queries more responsive. Consider reducing the number of tracked fields or shortening your retention period. Custom solutions could also be possible if you really need to track this data, but would probably involve a loss of reporting capability, if that mattered to you.

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.