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
Surender reddy SalukutiSurender reddy Salukuti 

getting error in opportunity teammember cration

Hi every one,

I am trying to inseart opportunityteammember it will getting error

error message -  Illegal assignment from List<Opportunity> to List<Opportunity>
Variable does not exist: id



trigger optTeam on Opportunity (after insert) {
    
    List<opportunity> opty = trigger.new;
    user u =[select id from user where alias='reddy    '];
    List<opportunityteammember> optyteam = new list<opportunityteammember>();
    
    for(opportunity op : opty){
        opportunityteammember opt = new opportunityteammember();
        opt.opportunityid=op.id;
        opt.teammemberrole='Hr';
        opt.userid=u.id;
        opt.opportunityaccesslevel='read';
     optyteam.add(opt);
      }
    
    insert optyteam;
  }
Murali MattaMurali Matta
Hi,

Use below code.
 
trigger optTeam on Opportunity (after insert) {
    
    //List<opportunity> opty = trigger.new;
    user u =[select id from user where alias='reddy'];
    List<opportunityteammember> optyteam = new list<opportunityteammember>();
    
    for(opportunity op : trigger.new){
        opportunityteammember opt = new opportunityteammember();
        opt.opportunityid=op.id;
        opt.teammemberrole='Hr';
        opt.userid=u.id;
        opt.opportunityaccesslevel='read';
     optyteam.add(opt);
      }
    
    insert optyteam;
  }

​​​​​​​Let me know if you have any confusion.

Kindly mark this as solved if the reply was helpful.

Thanks,
Murali
Khan AnasKhan Anas (Salesforce Developers) 
Hi Surender,

Greetings to you!

If there is any apex class with the same name of the standard or global sObjects while creating List, map, set the above error will reflect. In your organization, you might have created a class named "Opportunity". That is why the compiler is not able to understand that it is standard Object Opportunity or the class created in your org.

1. You need to rename your Apex Class to some other name.
2. Use 'Schema' before sObject while creating List, Set, Map (Don't use 'schema' before sObject in SOQL Query)
- List<Schema.Opportunity> oplist = new List<Schema.Opportunity>();
- return type should be also like List<Schema.Opportunity>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas