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
Glenn DalyGlenn Daly 

Bulification of SingleEmailMessage

I'm trying to bulkify my code, however I'm receiving the following error;

"Incompatible element type Messaging.SingleEmailMessage for collection of Opportunity".

What do I need to do to amend this so it works?   

    List<Opportunity>emailOpOwner = new list<Opportunity>();
            for(Opportunity opp : listOpportunity)
               Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

                    mail.setSenderDisplayName('Salesforce Support');
                for(opportunitylineitem oppLineItem :opp.opportunitylineitems)                
                    mail.setSubject('Historic Service attached to current opportunity : ' + oppLineItem.Product2.Name);
                    String body = 'Hi '+ opp.Owner.FirstName + ', ';     
                       body += '<br><br>Salesforce recognises you as the owner of the following opportunity:'+ opp.Name;
                  for(opportunitylineitem oppLineItem :opp.opportunitylineitems)
                      body += '<br><br>Attached to this opportunity is a former R&D service or project that is no longer available:' + oppLineItem.Product2.Name;
                       body += '<br><br> Please use the link below to view the opportunity record:';
                       body += '<br><br>'+;     
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                        update listOpportunity;
It is because of this line of code:
you are trying to add mail to a list of opportunity