Cause
TaroWorks Mobile Users on TaroWorks 7.4 have been deactivated or the profiles of the users have been changed and you are trying to edit Performance Target/Indicator.
Solution
Execute the below script:
//Map of PerformanceTarget__c vs Map of profile id vs count of tmus under that profile Map<Id, Map<Id, Decimal>> targetVsprofileVsCount = new Map<Id, Map<Id, Decimal>>(); //Map of profile id vs tmu count under that profile Map<Id, Decimal> profileVsTMUCount = new Map<Id, Decimal>(); for(gfsurveys__AssignedTarget__c a : [Select Id, Name,gfsurveys__User__r.gfsurveys__Profile__c, gfsurveys__User__r.gfsurveys__Profile_Id__c, gfsurveys__PerformanceTarget__c from gfsurveys__AssignedTarget__c]){ if(targetVsprofileVsCount.containsKey(a.gfsurveys__PerformanceTarget__c)){ Map<Id, Decimal> mapOfProfileVsCount = new Map<Id, Decimal>(); if(targetVsprofileVsCount.get(a.gfsurveys__PerformanceTarget__c).containsKey(a.gfsurveys__User__r.gfsurveys__Profile_Id__c)){ Decimal count = targetVsprofileVsCount.get(a.gfsurveys__PerformanceTarget__c).get(a.gfsurveys__User__r.gfsurveys__Profile_Id__c); mapOfProfileVsCount.put(a.gfsurveys__User__r.gfsurveys__Profile_Id__c, count+1); } else{ mapOfProfileVsCount.put(a.gfsurveys__User__r.gfsurveys__Profile_Id__c, 1); } targetVsprofileVsCount.put(a.gfsurveys__PerformanceTarget__c, mapOfProfileVsCount); } else{ Map<Id, Decimal> mapOfProfileVsCount = new Map<Id, Decimal>(); mapOfProfileVsCount.put(a.gfsurveys__User__r.gfsurveys__Profile_Id__c, 1); targetVsprofileVsCount.put(a.gfsurveys__PerformanceTarget__c, mapOfProfileVsCount); } } for(gfsurveys__TaroWorks_Mobile_User__c t : [Select Id, Name, gfsurveys__Profile__c,gfsurveys__Active__c,gfsurveys__Profile_Id__c from gfsurveys__TaroWorks_Mobile_User__c where gfsurveys__Active__c = true ]){ if(profileVsTMUCount.containsKey(t.gfsurveys__Profile_Id__c)){ profileVsTMUCount.put(t.gfsurveys__Profile_Id__c, profileVsTMUCount.get(t.gfsurveys__Profile_Id__c) + 1); } else{ profileVsTMUCount.put(t.gfsurveys__Profile_Id__c, 1); } } //Map of performance target id that is broken VS Profile Id for which it is broken Map<Id, Id> brokenTargetVsProfileId = new Map<Id, Id>(); for(Id key : targetVsprofileVsCount.keySet()){ Set<Id> profileIdsFromTarget = targetVsprofileVsCount.get(key).keySet(); for(Id profileId : profileIdsFromTarget){ if(profileVsTMUCount.containsKey(profileId)){ if(targetVsprofileVsCount.get(key).get(profileId) != profileVsTMUCount.get(profileId)){ brokenTargetVsProfileId.put(key, profileId); } } } } if(brokenTargetVsProfileId.size() > 0){ //Fetch all assigned targets for the performance target and profile and delete them List<gfsurveys__AssignedTarget__c> assignedTargetsToDelete = [Select Id From gfsurveys__AssignedTarget__c Where gfsurveys__PerformanceTarget__c In :brokenTargetVsProfileId.keySet() AND gfsurveys__User__r.gfsurveys__Profile_Id__c In :brokenTargetVsProfileId.values()]; if(assignedTargetsToDelete.size() > 0){ delete assignedTargetsToDelete; } }
If still encountering this issue please Submit a ticket.
Comments
0 comments
Please sign in to leave a comment.