1

I have the following class which I try to schedule from the anonymous window but this gives the error:

invalid type:abc_RiskSchedulerProcessor

Class

global class abc_RiskSchedulerProcessor implements System.Schedulable {
    global abc_RiskSchedulerProcessor() {

    }
    global void execute(System.SchedulableContext SC) {

    }
}

Anonymous window

Datetime sysTime = System.now();
sysTime = sysTime.addSeconds(5);
String chron_exp = '' 
                   + sysTime.second() + ' ' 
                   + sysTime.minute() + ' ' 
                   + sysTime.hour() + ' '
                   + sysTime.day() + ' ' 
                   + sysTime.month() + ' ? ' + sysTime.year();
abc_RiskSchedulerProcessor scheduler = new abc_RiskSchedulerProcessor();
System.schedule('RiskScheduler', chron_exp, scheduler);
7
  • If this is your exact code, I don't see an issue. I literally copy pasted the snippet here and tried replicating, and it just worked fine. – Jayant Das Feb 19 '19 at 15:58
  • 4
    Error states that you do not have the class named abc_RiskSchedulerProcessor in your org, double check if you are running script in right org's dev console. I ran the code in dev console without creating that class; gave same error as you. – Raul Feb 19 '19 at 15:58
  • 1
    @Raul You should add your comments as an answer as that seem to be the reason here. – Jayant Das Feb 19 '19 at 16:30
  • @Raul the class is in the org as I can schedule it in the declarative way could this be perhaps that the class version is incorrect? – Thomas Feb 19 '19 at 19:41
  • 2
    Is this class in a managed package by chance? – sfdcfox Feb 20 '19 at 4:59
3

In Apex Code, a class in a managed package has a "namespace." This is a prefix used by the platform to allow a managed package to have the same class name (and other things, like objects, fields, triggers, etc) as a class in your org. To use such a class in Apex, you need to include its namespace prefix. You can find this detail on the class' detail page, or by querying the ApexClass object. Once you find the namespace, you need to add it in your code:

Datetime sysTime = System.now();
sysTime = sysTime.addSeconds(5);
String chron_exp = '' 
                   + sysTime.second() + ' ' 
                   + sysTime.minute() + ' ' 
                   + sysTime.hour() + ' '
                   + sysTime.day() + ' ' 
                   + sysTime.month() + ' ? ' + sysTime.year();
theNS.abc_RiskSchedulerProcessor scheduler = new theNS.abc_RiskSchedulerProcessor();
System.schedule('RiskScheduler', chron_exp, scheduler);

Where theNS is the namespace of the class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.