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
kirkevonphillykirkevonphilly 

isArchived Event/Task Field

Hi all,

 

I have a scenario where I need to create test coverage for some code that deals with Archived Activities (Events and Tasks with  isArchived =  TRUE).


1)  Aside from setting SeeAllData = TRUE, is there any way to create a few Archived records?

 

2)  I tried updating my Activities per the criteria here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_guidelines_archive.htm, but it doesn't set isArchived to true for me.  I'm assuming this is some sort of nightly job?  If so, is there a system method that I can use to trigger this?  On the flip side, in a non-testing environment, if I update an Event or Task to violate the Archive criteria, isArchived is instantly updated to false.

 

Thanks in advance!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
1) No, because the field is read-only and the "archive bit" isn't toggled immediately when back-dating activities. Also, I wouldn't advise using SeeAllData just to satisfy your code; it's likely that someone later will unintentionally break your test code by making an executive decision to delete all tasks more than six months old. Trust me, it happens more frequently than you'd think.

2) It's not necessarily "nightly" (it's always day somewhere in the world), but it does run only infrequently, perhaps every 30 or 60 minutes, and definitely not anything you can control (at least, you can't set it to "true").

If you want your code coverage that badly, you'll have to work for it. I'd suggest using a static variable, and use that to simulate a query:

Event[] records = [SELECT ... ];
if( Util.pretendArchive )
records = Util.makeFakeEvents();
for(event record:records) {
...
}

Using this design, you can have mock records to use. I'd say you could try Test.loadData, but I don't think it'll allow bypassing audit fields, etc.

All Answers

sfdcfoxsfdcfox
1) No, because the field is read-only and the "archive bit" isn't toggled immediately when back-dating activities. Also, I wouldn't advise using SeeAllData just to satisfy your code; it's likely that someone later will unintentionally break your test code by making an executive decision to delete all tasks more than six months old. Trust me, it happens more frequently than you'd think.

2) It's not necessarily "nightly" (it's always day somewhere in the world), but it does run only infrequently, perhaps every 30 or 60 minutes, and definitely not anything you can control (at least, you can't set it to "true").

If you want your code coverage that badly, you'll have to work for it. I'd suggest using a static variable, and use that to simulate a query:

Event[] records = [SELECT ... ];
if( Util.pretendArchive )
records = Util.makeFakeEvents();
for(event record:records) {
...
}

Using this design, you can have mock records to use. I'd say you could try Test.loadData, but I don't think it'll allow bypassing audit fields, etc.
This was selected as the best answer
kirkevonphillykirkevonphilly

Thanks sfdcfox.

 

If anyone else has input on the infrequent nature of the updating of the isArchived field, please share.

 

EDIT:  Or if you have any ideas as to how to consistently generate isArchived Activities in a Dev org, I'd love to know.  I didn't see the archive bit flip for 24+ hours (checked at 24 hours later, no luck, then checked about 3 days later - bingo).

Akash PuneraAkash Punera
As per my knowledge, it archives activities every Saturday.