+ Start a Discussion
p1 force developerp1 force developer 

Best approach to change signature of a global apex class in a managed release package.

Hi ,

 

I want to know, what is the best approach to change signature of a global apex class in a managed release package.


We have some apex classes and web service in our managed release package which is already being used by several customers in different versions.

 

We need to add a new parameter to these classes and web services. 

 

I already know that we cannot change the signature of a global class or web service. I want to know if we introduce a new class with new signature then how do we handle the test methods and maintain backward compatibility.


Thanks

Imran MohammedImran Mohammed

One of the solutions could be to create a new method with same parameters as the old method in addition with the new parameter to it.

Also declare a new variable in the class that will hold the value of the new parameter added to the new method and this variable could be used in the old method.

In the added method, assign the above variable with the newly added paramater of the method.

Then invoke the actual method.

 

And in the test method just replace the old method with the new method.

 

 

 

p1 force developerp1 force developer

Thanks Imran,

 

I have already thought about creating new class with old paramters + the new parameter. This will require always maintaing the old class and its test method. I will have to create new test method for the new class.

 

If I replace old class with new class in the test method then I will loose test coverage for old class.

 

 

Also we have some web services which are calling this class. This will require changes to those web services as well.

 

Is there any way I can use package versioning

(e.g.

IF package version < 4.0 THEN use old class

ELSE use new class)