Search

Saturday 19 January 2013

Schedule Jobs Pending - Salesforce Deploy


I guess we all have had this error at some point "Schedule Jobs Pending" when deploying. This is caused because what you are deploying is used directly or indirectly by classes that are scheduled.

Lets say we have a class called schedClass which is scheduled. This class uses a class called Utils. If you change the Utils class and try to deploy it you will get the error.

Solution
1. Create an interface class
public Interface IUtils {}

2. Your Utils class now implements this interface
public virtual class Utils Implements IUtils{ }

3. Create another class which instantiates a class casted as IUtils the interface class of type Utils


public class UtilsProxy {
public static Type t = Type.forName('Utils');

public static IUtils thisutil = (IUtils)t.newInstance();

public static List<List<SObject>> breakIntoDMLChunks(List<SObject> theList, Integer chunkSize){
return thisutil.breakIntoDMLChunks(theList, chunkSize);
}

The result is any code that wants to run the Utils code can do so through the interface, so when you are deploying code which uses Utils just call the methods in the UtilsProxy class instead. Job done, no more Schedule Jobs Pending.