I'm creating an apex class that implements Schedulable and in the execute it queries a Custom Object but I can't understand why I'm getting this error when trying to query. Some other related questions (1, 2, 3)
- The object is created.
- User profile has access to the object and fields.
- There are no classes called from the new apex class I'm creating.
Code:
global class PopulatePreferences Field implements Schedulable {
public static String CRON_EXP = '0 30 10 * * ?';
global static String scheduleIt() {
PopulatePreferences sm = new PopulatePreferences();
return System.Schedule('Populate Preferred Artists Field', CRON_EXP, sm);
}
global void execute(SchedulableContext sc) {
List<Custom__c> preferences = [SELECT Prefered__r.Name, Client__c FROM Custom__c limit 10000];
List<Contact> contactsToUpdate = new List<Contact>();
for (Contact c : [SELECT preferences__c FROM Contact limit 10000]) {
for (Custom__c f : preferences) {
if (f.Client__c == c.Id) {
if (c.preferences__c != null)
c.preferences__c += '; ' + f.Prefered__r.Name;
else
c.preferences__c = f.Prefered__r.Name;
}
}
contactsToUpdate.add(c);
}
update contactsToUpdate;
}
}
When I run this code in our developer org it runs as expected, the problem is in the clients org where the Managed Package is installed.
Why could I be getting this error?