+ Start a Discussion
Jordan@BracketLabsJordan@BracketLabs 

APEX won't compile without chatter enabled.

I am running into a strange error where a set of APEX classes refuses to compile in a sandbox off a production org in Spring '12.

 

The managed package (our app) was installed successfully into the sandbox, but when the sandbox attempted to migrate to production there was a 'failure to load class named ... WebServicesClass.cls' error coming from a class that contained the keyword: WebService for the Ajax Toolkit for SOAP WebService Custom Methods.

 

After attempting to upgrade the API version of the class files we discovered that the classes and their members could not contain the notation of 'Public WebService' or it wouldn't compile. 

 

After using just 'WebService' the upgraded to API version v24, but this didn't solve our issue. Their continue to be load failure errors coming from some of these classes.

 

Strangly enough the sandbox wasn't 'Chatter' enabled (There was no warning that blocked us from installing the package when it was installed, it just wouldn't migrate), but turing Chatter ON caused all APEX Classes to compile normally.

 

The only 'Chatter' related method that referenced a field in Chatter (the installer didn't complain about it) worked like this:

 

public static Boolean doUserStatus(String status) {
       // User user;
		sObject user;
        try {
            //user = [SELECT Id, CurrentStatus from User where Id = :UserInfo.getUserId()];
        	String SOQL = 'SELECT Id, CurrentStatus from User where Id=\''+UserInfo.getUserId() +'\'';
        	//user = [SELECT Id, CurrentStatus from User where Id = :UserInfo.getUserId()];
       		user = database.query(SOQL);
        } catch (System.RequiredFeatureMissingException e) {
            //System.debug(e.getMessage());
            CampaignCalendarShared.errors = 'Chatter is not enabled for your organization.';
            return false;
        }

        if (!Schema.sObjectType.User.fields.CurrentStatus.isUpdateable()){
            // Insufficient privileges
            CampaignCalendarShared.errors = 'Chatter is not enabled for your user.';
            return false;
        }

        user.put('CurrentStatus',status);

        try {
            update user;
        } catch (System.DmlException e) {
            // DML query failed
            for (Integer i = 0; i < e.getNumDml(); i++) {
                if (e.getDmlType(i) == StatusCode.REQUIRED_FEATURE_MISSING) {
                    //System.debug(e.getMessage());
                    CampaignCalendarShared.errors = 'Chatter is not enabled for your organization.';
                }
            }
            return false;
        }

 I've commented out the old version, and updated it to use 'Dynamic SOQL' and 'sObject' references instead of direct references to the field 'CurrentUserStatus' as I thought this might be a component of 'Chatter' that the compiler didn't complain about on installation, but I'm not sure if this is a safe way to allow the class to compile without chatter enabled?

craigmhcraigmh

Yeah, it seems like SFDC has gotten more lax with validating deployments. I would just turn chatter off in your dev org unless you need to develop with it.