0

I get this error when I run the below code:

Method does not exist or incorrect signature: void schedule(String, String, PotentialCustomer) from the type System

Code:

global class PotentialCustomer implements Database.Batchable<sObject>{
    global string query;
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        query =  'select Id,Name from Potential_Customer__c where \'Service__c = 3G\'';
        system.debug('----list of records' + query);
        return Database.getQueryLocator(query);

    }
    global void execute(Database.BatchableContext bc , list<Potential_Customer__c> scope)
    {
       list<New_Campaign__c> temp = new list<New_Campaign__c>(); 
        for(Potential_Customer__c plist : scope)
        {
           New_Campaign__c nc = new New_Campaign__c();
            nc.Test__c = Potential_Customer__c.Id;
            nc.Name = Potential_Customer__c.Name;
            temp.add(nc);
        }
        insert temp;
    }

In Anonymous :

PotentialCustomer pc = new PotentialCustomer();
String jobId = System.schedule('jobName', '0 5 * * * ?',pc);
  • Please put all the code in your class – Akram G Dec 4 '17 at 13:27
1

I assume you are trying to schedule your batch apex class. Create a apex class that implement Schedulable interface. Once done, schedule that class either from execute anonymous or Setup->Apex Class-> Schedule apex

global class scheduledAClass implements Schedulable {
   global void execute(SchedulableContext SC) {
      PotentialCustomer potentialCusBatch = new PotentialCustomer(); 
      Database.executeBatch(potentialCusBatch);
   }
}

Schedule the above class using execute anonymous or from Setup

Example:

scheduledAClass pc = new scheduledAClass();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('A Job', sch, pc);

References -

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

https://help.salesforce.com/articleView?id=000171199&language=en_US&type=1

1

The system.schedule method only accepts a class instance which implements Schedulable as its third argument. It's most efficient to just include this implementation detail on your batch itself.

public with sharing class MyBatch implements Schedulable, Database.Batchable<SObject>
{
    public void execute(SchedulableContext context)
    {
        Database.executeBatch(this);
    }
    // batchable implementation below
}

Please note you do not need the global access modifier for batches/scheduled jobs. The public access modifier will suffice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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