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
Murali GuntakalMurali Guntakal 

Illegal assignment from LIST<Opportunity> to LIST<Opportunity>

Did anone face this issue in APEX Class?
 I a

Code
List<Opportunity> oppoList = [SELECT Id, Broker_Agent__c, Seller__c, Primary_Contact__c FROM Opportunity WHERE Id = : opportunityRoles.keySet()];

I am not getting this error in Prod but when I copied the code from Prod to Full sandbox, its failing deployment with Illegal assignment from LIST<Opportunity> to LIST<Opportunity> error. Not sure whats wrong. Any suggestion/info is appreciated.

Thanks 


 
Best Answer chosen by Murali Guntakal
Murali GuntakalMurali Guntakal
Looks like some one in my org has created a class names Opportunity and this created series of errors in existing class and test classes. Renamed the class Opportunity to new name and it that resolved the issue.

All Answers

Roy LuoRoy Luo
Try 'IN' instead of '='
 
List<Opportunity> oppoList = [SELECT Id, Broker_Agent__c, Seller__c, Primary_Contact__c FROM Opportunity WHERE Id IN :opportunityRoles.keySet()];

 
Murali GuntakalMurali Guntakal
Roy Luo, Thanks for your reply. I changed the code as suggested but I still get the same error message.
Error: Compile Error: Invalid initial value type LIST<Opportunity> for LIST<Opportunity> at line 502 column 38
 
AshlekhAshlekh
Hi Murali,

You need to run below query in developer console. If it work in developer console than it mean error is not in query, you are looking error at wrong place.
Map<id,Opportunity> opportunityRoles = new Map<id,opportunity>([select id from opportunity limit 5]);
List<Opportunity> oppoList = [SELECT Id, Broker_Agent__c, Seller__c, Primary_Contact__c FROM Opportunity WHERE Id IN :opportunityRoles.keySet()];

 
Murali GuntakalMurali Guntakal
Looks like some one in my org has created a class names Opportunity and this created series of errors in existing class and test classes. Renamed the class Opportunity to new name and it that resolved the issue.
This was selected as the best answer
Anoop yadavAnoop yadav
Hi,

Have you created any class with "Opportunity" Name, if yes, delete that class.
else use the below code.
List<Schema.Opportunity> oppoList = [SELECT Id, Broker_Agent__c, Seller__c, Primary_Contact__c FROM Opportunity WHERE Id IN :opportunityRoles.keySet()];