function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shruthi Vasudeva 7Shruthi Vasudeva 7 

Getting production deployment error dependent class is invalid and needs recompilation

Hi Master developers,
  I am an Admin at a non-profit with newbie to development and need your help! I am trying to deploy a small change from Sandbox to Production , but faced with 'dependent class is invalid and needs recompilation' for all my Apex classes. The change I did was - on a Schedulable batch job ,I removed the insert statement from Finish method to the execute method as I was getting the system limit exception DML rows >10001 (old code , but may be we have too many records now).

My code below -
global void checkCollege(ID college,ID studentID){
        CommunitiesUserPermissionService.ContactShareMatch existingContactSharingRule = null;
        if(existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id) != null) {
            existingContactSharingRule = existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id).get(studentID);
        }
        
        if (existingContactSharingRule == null) {
            system.debug('making sharing rule');
            ContactShare cs = new ContactShare();
            cs.contactAccessLevel = 'Edit';
            cs.userOrGroupId = groupMap.get('grp_' + college).Id;
            cs.contactId = studentID;
            csList.add(cs);
            CommunitiesUserPermissionService.ContactShareMatch csm = new CommunitiesUserPermissionService.ContactShareMatch();
            csm.matchFound = true;
            csm.rule = cs;
            if(existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id) == null) {
                existingGroupSharingRulesMap.put(groupMap.get('grp_' + college).Id, new Map<Id,CommunitiesUserPermissionService.ContactShareMatch>());
            }
            existingGroupSharingRulesMap.get(groupMap.get('grp_' + college).Id).put(studentID, csm);
        } else {
            existingContactSharingRule.matchFound = true;
            System.debug('Existing Rule ' + existingContactSharingRule);
        }
    }
         
    global void execute(Database.BatchableContext BC, List<Application__c> scope) {
        for (Application__c ap : scope) {
            // check school_name and Mid_Year_transfer, each calling the same method.
            // 
            System.debug('School Name: '+ap.School_Name__c+', groupMap get result: '+groupMap.get('grp_' + ap.School_Name__c));
            if (ap.School_Name__c != null && groupMap.get('grp_' + ap.School_Name__c) != null) {
                checkCollege(ap.School_Name__c,ap.student_name__c);
            }
            System.debug('School Name: '+ap.Mid_Year_Transfer_School__c+', groupMap get result: '+
                         groupMap.get('grp_' + ap.Mid_Year_Transfer_School__c));
            if (ap.Mid_Year_Transfer_School__c != null && ap.Mid_Year_Transfer_Status__c == 'Approved' && 
              groupMap.get('grp_' + ap.Mid_Year_Transfer_School__c) != null) {
                checkCollege(ap.Mid_Year_Transfer_School__c,ap.student_name__c);
            }
            
        }
        system.debug('cslist' +  csList);
        if (!csList.isEmpty()) insert csList;     
        cslist.clear();        - Changes here , so that the data is inserted every time the batch is processed and we dont hit the DML limit exception

        
    }

    global void finish(Database.BatchableContext BC) {
        //System.debug(csList);
        //if (! csList.isEmpty()) insert csList;   -Moved this to the execute batch method to resolve the DML system limit exception error
    }




After fixing this , the code ran successfully in Full sandbox but when I deploy I see this error. 
User-added image

Any input is greatly appreciated. 
Thanks!
Best Answer chosen by Shruthi Vasudeva 7
Uttpal_ChandraUttpal_Chandra
Shruthi try compiling all classes in Sandbox and then deploy.

All Answers

Uttpal_ChandraUttpal_Chandra
Hi Shruthi,

Go to the below link.

https://help.salesforce.com/articleView?id=000340653&type=1&mode=1 (https://help.salesforce.com/articleView?id=000340653&type=1&mode=1)

Regards,
Uttpal Chandra
Shruthi Vasudeva 7Shruthi Vasudeva 7
Thanks uttpal, I already tried that . Compiling all the classes in Production. Should that be done in the Sandbox and brought over? I however do not have the Compile all triggers link. 
Uttpal_ChandraUttpal_Chandra
Shruthi try compiling all classes in Sandbox and then deploy.
This was selected as the best answer
Shruthi Vasudeva 7Shruthi Vasudeva 7
Thank you Uttpal, that worked.