3

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?

2
  • Are you positive (Seen with your own eyes) that the user who scheduled the batch has access to the objects (Should not be an issue) and that the API name of the object is namespace__Custom__c? Have you tried the query in the DE console of the target org?
    – Eric
    Commented Sep 10, 2014 at 18:27
  • Thanks @Eric, turns out it was missing the namespace for both the Object and the Fields, didn't know it was necessary. Please copy this comment as an answer to select it.
    – Jose
    Commented Sep 10, 2014 at 21:04

1 Answer 1

0

Are you positive (Seen with your own eyes) that the user who scheduled the batch has access to the objects (Should not be an issue) and that the API name of the object is namespace__Custom__c? Have you tried the query in the DE console of the target org?

You must log in to answer this question.

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