I have a global class in a managed package like this:
global with sharing class MyClass {
/*
* class members, constructors, methods, etc
*/
public List<Lead> getRecentlyViewedLeads () {
List<RecentlyViewed> viewed = [SELECT Id FROM RecentlyViewed WHERE Type = 'Lead' LIMIT 20];
List<Contact> contacts = new List<Contact>();
for (RecentlyViewed view : viewed) {
contacts.add(new Contact(Id = view.Id));
}
return contacts;
}
}
It is more complicated than that, but this should be sufficient to demonstrate the issue. When one of my customers updates objects in Salesforce and runs their unit tests, they see compilation errors and unit test errors in their code, until they recompile my managed package. The errors are all look similar to:
line -1, column -1: Previous load of class failed: MYPACKAGE.MyClass: line XXX, column YY: sObject type 'RecentlyViewed' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
The details of the inheritance chain can change from error to error (it sometimes starts from a class that inherits from MyClass
), but they all reference the same line selecting from the RecentlyViewed
object in MyClass.getRecentlyViewedLeads
.
While this class is global, the customer claims not to be referencing it in their code. The customer pushes code changes to their Salesforce sandbox on a daily basis, and gets these errors every single time. Recompiling my managed package after pushing their code changes resolves the problem and allows their unit tests to pass.
I would normally associate that error with a permissions problem (where the user running the code cannot see the RecentlyViewed
object), but since the problem disappears after recompilation, I feel that this is unlikely to be correct.
What I would like to know is:
- could this be as simple as a permissions issue?
- would changes to standard objects (Contacts, Leads, etc) propagate to the RecentlyViewed object, requiring my managed package to be recompiled to take them into account?
- is there some other issue that might cause the
RecentlyViewed
object to behave this way? - why might a customer's own code care whether there were compilation issues in an installed managed package, if it never references anything in that managed package?