Skip to main content
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. 

Getting production deployment error dependent class is invalid and needs recompilation

Any input is greatly appreciated. 

Thanks!
답변 4개
  1. 2020년 1월 24일 오전 5:42
    Shruthi try compiling all classes in Sandbox and then deploy.
0/9000