function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CarlBCarlB 

Dynamic query yields incompatible SObject type

Hello.

I have a managed package that is build on another managed package.  In particular I have interfaces in one managed package that extend (global) interfaces in the other managed package (e.g.
 
MANAGED PACKAGE A:

global interface A {

    void A();
}


MANAGED PACKAGE B:

global interface B extends A.A {

}
)

Normally this doesn't cause a problem, but recently I tried to install my managed package in an org and the install failed saying the method A() didn't exist in interface B, which clearly it does.

I got around this by changing my code to explicitly reference interface A rather than interface B, e.g.
 
ORIGINAL CODE:

B b = ....

b.A();




NEW CODE:

B b = ...

A a = (A)b;
a.A();


This got around the problem, but once I had uploaded a new version of managed package B, some of the unit tests started failing with the error:
 
Dynamic query yields incompatible SObject type B.B for loop variable of type A.A
These unit tests worked before, but it seems that Salesforce has go in a mess.

Can anyone offer a workaround?

Regards,

Carl




 
CarlBCarlB
Well, no thanks to Salesforce, I managed to come up with a work-around.

In my parent managed package (A), I had some code that included this:
 
for (A a : listOfAs) {
    a.A();
}
The listOfAs included instances that implemented B.  The exception was thrown by the "for..." line.

By changing the code to
 
for (Object a : listofAs) {
    ((A)a).A();
}
It worked.