+ Start a Discussion
bedhesbedhes 

Apex Scheduler error: "Global type must be contained inside of a global class"

Hello,
I have a big problem with apex scheduler. I've always get this error message, when I try to execute the scheduler: "Global type must be contained inside of a global class"
Can anyone give me a hint on this? Below is part of my code:
global class updateData implements Schedulable {
  global void execute (SchedulableContext SC) {
     DataContact dContact = new DataContact();
     dContact.UpdateContact();
  }
}
Thanks!

 

Gunners_23Gunners_23

I guess instead of executing the batch you're trying to call some function of the batch

 

Use database.execute(dContact ,200) instead of dContact.UpdateContact()

iBr0theriBr0ther

Where is DataContact?

bedhesbedhes

Hi all,

 

basically with the apex scheduler, I want to update my custom contact List with adding a new contact.

Here is my DataContact class:

public class DataContact {
    public void UpdateContact() {
	      List<Custom_Contact__c> contactLists = new List<Custom_Contact__c>();
	      contactLists = [SELECT Id FROM Custom_Contact__c];
	      
	      Custom_Contact__c newContact = new Custom_Contact__c ();
	      newContact.Contact_Person__c = 'John Doe';
	      newContact.Company_Name__c = 'Salesforce';
	
	      insert newContact;
	      contactLists.add(newContact);
    }
}

And I set the scheduled Time through the UI by Schedule Apex button. 

 

any comment guys?

Thanks for the input..

 

iBr0theriBr0ther

You may check all classes and methods if there is class or method decleared as Global in the public class.

Anup JadhavAnup Jadhav

Hello,

 

I'd rewrite the global class as follows:

 

global class UpdateData implements Schedulable {
  global DataContact dContact;
  global void execute (SchedulableContext SC) {
     dContact = new DataContact();
     dContact.UpdateContact();
  }
}

 

   - anup

Patcs_1Patcs_1

Hi bedhes

 

Have you resolved this error?

 

Thanks

Priya