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
Caroline Poole 9Caroline Poole 9 

Schedulable Apex Class - Text Class

I created a schedulable apex class that deletes Marketo Activities in salesforce after a week so our activity volume doesn't get too high.

Is anyone able to help me write a test class for this? Or give me guidance? THANK YOU!!

----

global class DeleteMarketoActivities implements Schedulable{
    global void execute(SchedulableContext SC) {
        List<Task> Obj = [select Id FROM Task WHERE CreatedById = '0050a00000GeV2hAAF' AND CreatedDate != LAST_N_DAYS:7];
            delete Obj;
    }
}
AnudeepAnudeep (Salesforce Developers) 
Hi Caroline, 

Posting a simple test class here. Let me know if it gives you any coverage
 
Test.startTest();
DeleteMarketoActivities sh1 = new DeleteMarketoActivities();
String sch = '0 0 2 * * ?'; 
system.schedule('Test Marketo Activities', sch, sh1); 
Test.stopTest();
// add system asserts to check your expected behaviour

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you