Search code examples
salesforceapex-codeforce.com

Why can't class relationships in Salesforce managed packages be changed?


I have written an Apex class in a Salesforce managed package which uses the managed version of the apex-lang library package:

global class MySorter implements al.Objectcomparator

I am considering eliminating the dependency on the managed package by distributing apex-lang with my package. Having installed the unmanaged version of apex-lang, I try changing my class:

global class MySorter implements Objectcomparator

Upon trying to save, I get an error:

Error: Compile Error: Required class relationships must be maintained: MySorter Implements al.ObjectComparator[Previously Managed] at line 1 column 8

Why would such a restriction be in place? Any ideas on getting around it?


Solution

  • The restriction is in place to stop you changing your contract with code outside of your package. there could be callers of this code from outside your package (because you marked it global), that rely on it implementing the al.ObjectComparator interface, if you make the change you'd like to, you'd break that code when they upgrade.