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
Louis-Paul ValadouxLouis-Paul Valadoux 

Calling component from another component doesn't work while the component works perfectly alone (sendEmail)

Hello,

I am trying to send an email to all selected users in a related view. My issue is that I don't understand why my email is not sending when I call sendEmail from MyAccountIDExt while it's working well when I call it directly from EmailUtil. Any ideas why ? 

Here are my codes - please note that I've changed the email adresses:
MyAccountIDExt
public class MyAccountIDExt
{
    public List<Pipe_Owner__c> memList {get;set;}
    private ApexPages.StandardSetController standardController;
    private Set<Id> memIds = new Set<Id>();

    public MyAccountIDExt(ApexPages.StandardSetController standardController){
        this.standardController = standardController;
        
        memList = new List<Pipe_Owner__c>();
        for (Pipe_Owner__c mem : (List<Pipe_Owner__c>)standardController.getSelected()){
            memIds.add(mem.Id);
        	
        }
        memList = [SELECT Name, eMail_address__c FROM Pipe_Owner__c WHERE ID IN: memIds];
        
        throweMailMethod('LPV', 'test@company.com'); 
   
    }
        
    public void throweMailMethod(String valName, String valeMail){
		  
		List<String> toAddresses = new List<String> {'test@company.com'};
        //toAddresses.add(Pipe_Owner__c.eMail_address__c);
        
        String replyToAddress = 'test@company.com';
        
        //use the new util class to send an email
        EmailUtil emailUtil = new EmailUtil(toAddresses);
        
        //send plain text body
        emailUtil.plainTextBody(valName + ', - This is a test.')
             .senderDisplayName('Administrator')
             .replyTo(replyToAddress)
             .sendEmail();

    }

}

EmailUtil:
public class EmailUtil {
       private Messaging.SingleEmailMessage singleEmailMessage;
       private final List<String> toAddresses;
       
       //optional parameters set to default        
       private String subject = '';
       private String htmlBody = ''; 
       private Boolean useSignature = false;
       private List<Messaging.EmailFileAttachment> fileAttachments = null;
       //defaults to current user's first name + last name
       private String senderDisplayName = UserInfo.getFirstName()+' '+UserInfo.getLastName();
       //get the current user in context
       User currentUser = [Select email from User where username = :UserInfo.getUserName() limit 1];        
       //replyTo defaults to current user's email 
       private String replyTo = currentUser.email;
       private String plainTextBody = '';
       
       public EmailUtil(List<String> addresses) {
           this.toAddresses = addresses;
       }
       
       public EmailUtil senderDisplayName(String val) {
           senderDisplayName = val;
           return this;
       }
       
       public EmailUtil subject(String val) {
           subject = val;
           return this;
       }
       
       public EmailUtil htmlBody(String val) {
           htmlBody = val;
           return this;
       }
       
       public EmailUtil useSignature(Boolean bool) {
           useSignature = bool;
           return this;
       }
       
       public EmailUtil replyTo(String val) {
           replyTo = val;
           return this;
       }
       
       public EmailUtil plainTextBody(String val) {
           plainTextBody = val;
           return this;
       }
       
       public EmailUtil fileAttachments(List<Messaging.Emailfileattachment> val) {
           fileAttachments = val;
           return this;
       }
       
       //where it all comes together
       //this method is private and is called from sendEmail()
       private EmailUtil build() {
           singleEmailMessage = new Messaging.SingleEmailMessage();
           singleEmailMessage.setToAddresses(this.toAddresses);
           singleEmailMessage.setSenderDisplayName(this.senderDisplayName);
           singleEmailMessage.setSubject(this.subject);
           singleEmailMessage.setHtmlBody(this.htmlBody);
           singleEmailMessage.setUseSignature(this.useSignature);
           singleEmailMessage.setReplyTo(this.replyTo);
           singleEmailMessage.setPlainTextBody(this.plainTextBody);
           singleEmailMessage.setFileAttachments(this.fileAttachments);
           return this;
       }
       
       //send the email message
public void sendEmail() {

        // build and send email.

        build();

        last_sendEmail_result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { singleEmailMessage });

    }
public static Messaging.SendEmailResult[] last_sendEmail_result {get; private set;}

//custom exception		
public class GenericException extends Exception{
	
}    
           
   }

and the VF page:
<!--<apex:page controller="TestSendEmail" action="{!throweMailMethod}">
<apex:form>
<apex:inputHidden value="{!case.OwnerId}"/>
</apex:form> 
</apex:page>-->

<apex:page standardController="Pipe_Owner__c" extensions="MyAccountIDExt" recordSetVar="Member">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!memList}" var="M">
            <apex:column value="{!M.Name}"/>
            <apex:column value="{!M.eMail_address__c}"/>

        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>