• Puja Priya
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
How to Write Test Class for Scheduled Apex Class? I manage to write Schedule class but I need help to write test class for this. I am learning Apex code. I would be grateful if someone can help me out. 

public class DeactivateInactiveUsers implements Schedulable {
    public void execute(SchedulableContext context) {
        User[] selectedUsers = [SELECT Id FROM User WHERE IsActive = TRUE AND Id NOT IN (SELECT UserId FROM LoginHistory WHERE LoginTime = LAST_N_DAYS:30)];
        for(User record: selectedUsers) {
            record.IsActive = false;
        }
        Database.update(selectedUsers, false);
    }
}
Here is my code.

//Controller
public with sharing class deleteEvents implements Schedulable
{
    
      public void execute(SchedulableContext SC) 
       {
           
            
            List<Login__c> query=[SELECT Id, Name FROM Login__c WHERE CreatedDate != LAST_N_DAYS:10 and CreatedDate < today ];
            
        List<Login__c> con= query;
        
        if(con!=null)
        {
            delete con;
            }
        }
}

//testclass
@isTest
private class deleteeventsTest{
static List<Login__c> logins = new List<Login__c>();

static testmethod void Test(){
Test.StartTest();


//insert test data
Login__c log=new Login__c();
//fill all mandatory fields needed
log.Name ='testing';
log.Email__c='test@gmail.com';
insert log;

deleteEvents deleve=new deleteEvents();
deleve.execute();
String schedule = '0 15 12 15 1-12 ? *';
List<Login__c> objectList = new List<Login__c>(); 
Test.stopTest();
}
}

I am getting Error: Compile Error: Method does not exist or incorrect signature: [deleteEvents].execute() at line 17 column 1
Please help as how to solve it?

I created a custom button (list button) on Accounts and am now trying to add it to the page layout. However, I can't find the option on the edit layout screen! When I make it a custom link, I can find it under "Custom links" but I really want it to be a button. Am I looking in the right place, or is there something else I have to do to make it show up?

Thanks!

  • March 28, 2010
  • Like
  • 0