1

My flow type is autolaunched flow , the goal of the flow is to send Emails.

enter image description here

I want to call this flow from Apex , besides i want to fill these fields : EmailAddresses and SenderAddress in Apex and pass it to flow - How can i achieve this as i didn't find any documentation.

1

1 Answer 1

2

You use the Flow.Interview class to create and execute flows. First, create a Map of parameters to use, create a new Interview, and then start it. Here's the example from the documentation:

  Map<String, Object> inputs = new Map<String, Object>();
  inputs.put('AccountID', myAccount);
  inputs.put('OpportunityID', myOppty);
  
  Flow.Interview.Calculate_discounts myFlow = 
    new Flow.Interview.Calculate_discounts(inputs);
  myFlow.start();
2
  • If my case , i want to fill EmailAddresses and SenderAddress with Case's custom fields So my code should be like : Map<String, Object> inputs = new Map<String, Object>(); inputs.put('Case.Customfield', myAccount); inputs.put('Case.Customfield', myOppty); Flow.Interview.Calculate_discounts myFlow = new Flow.Interview.MyFLOWNAME(inputs); myFlow.start(); myAccount and myOppty are Flow's variables - can you confirm?
    – user107320
    Commented Nov 23, 2021 at 16:49
  • 1
    @Adam You need the API name for each input variable (you've got the key/value backwards), it would look more like: inputs.put('emailAddresses',new String[] { myCase.ContactEmail }); inputs.put('senderAddress', UserInfo.getUserEmail());
    – sfdcfox
    Commented Nov 23, 2021 at 16:56

You must log in to answer this question.