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
luckymeluckyme 

Invalid conversion from runtime type <class> to <interface>

I am getting a strange error message as above.

 

I have an interface {say A} which has one method. I have a class {say B} that implements the interface (the method). And I have another class/method that takes interface A as a parameter. And I call that method with an instance of the class B. All compiles ok. But I got the error when running it.

 

I do not see what can possibly be wrong with my code. If I do not implement the method in A, it fails to compile. If I remove 'implements A' from B, it fails to compile. Also I have another class {C} that implements the interface A, and is used in exact same way and it works fine.

 

Anyone has seen similar issues?

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

Keith987Keith987

I am seeing the same problem but in a somewhat obscure combination of managed packages and triggers. If you solved your problem please post the solution here as that may help me.

 

Thanks,

Keith

Keith987Keith987
This was selected as the best answer
craigmhcraigmh

Yes, it's always a good idea to develop against the latest version. Apex changes a fair bit with each version, so it's always best to make sure the full feature list is available to you.

 

If you look at the list of reserved keywords:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_reserved_words.htm

 

You'll see that there quite a few to come. With the documentation referring to the current version of Apex, that's what you should be developing against. Whenever a new version comes out for my dev instance, the first thing I do is change the version of all of my classes/triggers/etc.

Keith987Keith987

To be clear here, the version issue was not with the "Salesforce.com API" where code locked to one version will continue to work against future versions of the platform. But rather that some source code that depended on a managed package broke when the managed package was upgraded which is a failure of the aimed for backward compatibility of managed packages.

Afzal MohammadAfzal Mohammad
@luckyme did you get this working? I am stuck with a same issue. fyi, I am on the latest version.