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
sowmya thotthadisowmya thotthadi 

Error: SendMailController Compile Error: Method does not exist or incorrect signature: void split(String) from the type List<String>

public class SendMailController {

    public String z { get; set; }
     public String y { get; set; }
    public String x { get; set; }
    public String attachname{get ; set;}
    public blob attachbody{get; set;}
    public void saveMethod() {
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};   
        mail.setToAddresses(xyz.split(';'));
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        
        Messaging.EmailFileAttachment fattch = new Messaging.EmailFileAttachment();
        fattch.setFileName(attachname);
        fattch.setBody(attachbody);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {fattch});
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
   }
  }
Raj VakatiRaj Vakati
Line  mail.setToAddresses(xyz.split(';')); should be mail.setToAddresses(xyz) . Here is the code
 
public class SendMailController {
    
    public String z { get; set; }
    public String y { get; set; }
    public String x { get; set; }
    public String attachname{get ; set;}
    public blob attachbody{get; set;}
    public void saveMethod() {
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};   
            mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        
        Messaging.EmailFileAttachment fattch = new Messaging.EmailFileAttachment();
        fattch.setFileName(attachname);
        fattch.setBody(attachbody);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {fattch});
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
}

 
sowmya thotthadisowmya thotthadi
Hi,
i want to given more than one email id's so i had split in that way 
sowmya thotthadisowmya thotthadi
Error :SendMailController Compile Error: Initial expression is of incorrect type, expected: String but was: List<String> at line 11 column 23
public class SendMailController {

    public String z { get; set; }
    public String y { get; set; }
    public  String x { get; set; }
    public String attachname{get ; set;}
    public blob attachbody{get; set;}
    public void saveMethod() {
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x.split(';',0)};   
        mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        
        Messaging.EmailFileAttachment fattch = new Messaging.EmailFileAttachment();
        fattch.setFileName(attachname);
        fattch.setBody(attachbody);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {fattch});
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
   }
  }