0

I have created a schedulable class

global class ScheduledClassTesting Implements Schedulable{

    global void execute(SchedulableContext sc)
    {
         testScheduleClass();
         System.abortJob( sc.getTriggerId() );
      }

    public void testScheduleClassMethod(string argPass){

    }

}

However it doesnot allow me to save as it give the following error(which makes sense).

Save error: Method does not exist or incorrect signature: testScheduleClass()

Is it possible to create a method similar to testScheduleClassMethod() which accept's an argument(type string) at the time it is being scheduled?

3

2 Answers 2

1

What about this:

global void execute(SchedulableContext sc)
{
     string test='';
     testScheduleClassMethod(test);
     System.abortJob( sc.getTriggerId() );
  }

public void testScheduleClassMethod(string argPass){

}
7
  • Yes, this allows me to save the code without any errors. But is there a way to pass the argument while I am scheduling it? Is so will this statement string test=''; override the value being passed?
    – Yash Mehta
    Commented Aug 14, 2013 at 19:37
  • Where is the argument originating from?
    – Phil B
    Commented Aug 14, 2013 at 19:42
  • I am scheduling the function using System.schedule('TestSchedule' + sysTime, chronExpression, new ScheduledClassTesting ()). I want to pass it at the time of schedule along with ...new ScheduledClassTesting ()).
    – Yash Mehta
    Commented Aug 14, 2013 at 19:52
  • so basically the argument will be passed at the time the class is scheduled.
    – Yash Mehta
    Commented Aug 14, 2013 at 19:53
  • 1
    Hm its hard to know what's going on without seeing the code, but you don't need to instantiate the class. Take a look at this example of accessing a static variable in another class: salesforce.com/docs/developer/cookbook/Content/… Hope that helps
    – Phil B
    Commented Aug 16, 2013 at 15:16
1

What about passing parameters through constructor and storing them in global instance variables?

global class Dummy_Schedulable_Class implements Schedulable{ 

    global List<String> names;
    global List<String> cronExpressions;

    global void execute(SchedulableContext SC) {
        System.debug(LoggingLevel.ERROR, names );
        System.debug(LoggingLevel.ERROR, cronExpressions );
        testScheduleClassMethod(names[0]);
    }

    public void testScheduleClassMethod(string argPass){

    }

    public Dummy_Schedulable_Class ( List<String> aNames, List<String> aCronExps) {
        if ( names == null ) {
            names = aNames;
        } else {
            names.addAll(aNames);
        }
        if ( cronExpressions == null ) {
            cronExpressions = aCronExps;
        } else {
            cronExpressions.addAll(aCronExps);
        }
    }

}

Not the answer you're looking for? Browse other questions tagged .