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
Mike FuchsMike Fuchs 

Help With Apex Autolaunched Flow Code

Apex noob here. So I was hoping to launch this flow through Process Builder, but since there is a known bug that process builder can't process flows from custom objects in managed packages, (and since flow triggers can no longer be requested for new orgs) I'm stuck using Apex to launch this flow.

In summary I want this flow to fire when a new record is created for the custom "Project" object (API name pse__Proj__c). I will be passing 2 input variables to the flow called VarProjID and VarSoftwareName. The ProjID variable comes from the Salesforce ID of the Project and the VarFMSCategory comes from the Opportunity (Software_Category_c custom field) that spawned the project. The flow I am calling is called, Practice_Flow_Update. I know the flow works, but when this trigger executes nothing happens. I'm hoping it is just simple user error on my part. Perhaps it is the way I'm passing in the variables. I took some code I found from searching Google, and modified it a bit to fit my need. Please help and I appreciate it!!!!

trigger CallMyFlow on pse__Proj__c (after insert) {

for (pse__Proj__c proj : Trigger.new) {
    Map<String, Object> params = new Map<String, Object>();
    params.put('ProjId', proj.Id);
    params.put('varFMSCategory', proj.pse__Opportunity__r.Software_Category__c);
    Flow.Interview.Practice_Flow_Update practiceFlow = new Flow.Interview.Practice_Flow_Update(params);
    practiceFlow.start();
}
}
Mike FuchsMike Fuchs
To follow-up, I know the problem is the way I am passing my variables.  I just created a dummy flow where it ignores the input variables, and it worked when I called it from the Apex trigger.  Now if someone can tell me the proper syntax on how to pass variables to the flow, I'll be very happy!!  Please help!