//trigger code

trigger mailsentcreateaccusindtri on Account (after insert) 
    //list<string> mail= new list<string>();
    if(trigger.isafter && trigger.isinsert)
          list<string> mail= new list<string>();

        list<user> u=[select id, name, email from user where profile.name = 'system administrator'];
        for(user us: u)
        for(account acc: trigger.new){
            messaging.SingleEmailMessage mg= new messaging.singleEmailmessage();

            mg.setToaddress(new string[] {mail});
            mg.setSubject('New account cretaed on '+acc.createddate);
            mg.setPlainTextBody('New account has been created with the name of '+acc.name);

            list<messaging.SingleEmailMessage> messages= new list<messaging.SingleEmailMessage>();


  • 2
    I believe your error is in this line? mg.setToaddress(new string[] {mail}); If yes, you are creating a new list of string and add on that another list of string. You could change only by mg.setToaddress(mail); – m Peixoto May 31 '19 at 8:57

The mg.setToaddress() method expects a parameter of type List<String> as you already know.

And your mail variable is already of type List<String>.

So you don't need to insert it inside a new array of type String.

The right code is: mg.setToaddress(mail);

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.