1

We have a flow that stores the collection of Ids with Email address and we want to pass those Ids to send an email from Apex. I'm Trying to call the apex but it gives me error list has no rows. Couldn't find the any answer. I'm not sure how to pass the Multiple Email parameters from Invocable.

Updated Code & Screen shot. I need to be able to pass the correct Email address collection to the Apex invocable parameter string. Could you please tell me where I'm doing wrong? Do i still require loop variable?

enter image description here enter image description here enter image description here

public class SendEmailAction {
    @InvocableMethod(label='Send SE Email Notification') 
public static void SendSENotification(List<string> Emailaddresses){
    
        List<OrgWideEmailAddress> lstEmailAddress=[select Id from OrgWideEmailAddress WHERE Address='tripss@rush.edu'];
        List<EmailTemplate> SEEmailTemplate= [Select Id, Name, DeveloperName from EmailTemplate where DeveloperName= 'Safety_Event_New_Event_Reported'];
         
         Messaging.SingleEmailMessage[] mails = new Messaging.SingleEmailMessage[0];
            
        for(string Ids : Emailaddresses) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setTemplateId(SEEmailTemplate[0].Id);
        mail.setTargetObjectId(UserInfo.getUserId());
        mail.setToAddresses(RecepientList);
        mail.setSaveAsActivity(false);
        mails.add(mail);
        mail.setOrgWideEmailAddressId(lstEmailAddress[0].Id);
        }
       Messaging.sendEmail(mails);
    }
 }      
1
0

Inside your Apex Action, under the Set Input Values section you need to ensure that you have checked/moved the slider to include your input.


Invocable methods can be hard to wrap your mind around sometimes, because when you see that it takes a List<DATATYPE> as input, you actually send it a single DATATYPE from the Flow. If you want to be able to send it a list (a collection) from the Flow, then you need to change the method to take a List<List<DATATYPE>>.

Since you have a collection variable that holds your emails, you might want to change your Apex method to take a List<List<String>> Emailaddresses. That way you can call your Apex Action at the end of your Loop (After Last Item) instead of calling it once per email address in the midst of your Loop.


EDIT

[It was late for me and I forgot to include this for more completeness.]

You could instead add an Invocable Variable[*] inside a separate inner class, which essentially is used as a wrapper for input (and can be used for any output), and can make it more generic. However, Invocable Variables like this can add more layers of complexity (and confusion for those not fully comfortable with Invocable Methods), so it is not always a good thing if you do not need it.

[*] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm

0

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.