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
DixitSDixitS 

Not able to call flow From Apex code, Trying from Anonymous Block

Map<String, Object> myMap = new Map<String, Object>();
myMap.put('removedPartId ', 'a0L1500000Mjavp');
Flow.Interview.FindPRC findPrcFlow= new Flow.Interview.FindPRC(myMap);
findPrcFlow.start();
Best Answer chosen by DixitS
Agustina GarciaAgustina Garcia
Hi,

Do you get any error? I tried something by my side and made it work.

This is my code:
 
Map<String, Object> params = new Map<String, Object>();
params.put('opportunityId', '006b000000NfSk4');
        
Flow.Interview.DeleteAccountFlow flowToRemoveAcc = new Flow.Interview.DeleteAccountFlow(params);
flowToRemoveAcc.start();
        
String theOppId = (String)flowToRemoveAcc.getVariableValue('opportunityId');
System.debug('SF theOppId = ' + theOppId);

My advices:

1. Be sure that your variable removedPartId is the one you have in your flow, and it is well written. In my case, I also check the opportunityId value at the end to be sure it is well retrieved in the flow.
2. Double check the id. Does it exist?
3. Be sure your flow name is ok. FindPRC  should be the UniqueName field

If your code is fine, let's check the Flow

1. Be sure your flow type is Autolaunched Flow otherwise you cannot call it directly from code.
2. Be sure that your removedPartId variable type is Text (for Ids) and also type is Input / output

Does it work?

All Answers

Agustina GarciaAgustina Garcia
Hi,

Do you get any error? I tried something by my side and made it work.

This is my code:
 
Map<String, Object> params = new Map<String, Object>();
params.put('opportunityId', '006b000000NfSk4');
        
Flow.Interview.DeleteAccountFlow flowToRemoveAcc = new Flow.Interview.DeleteAccountFlow(params);
flowToRemoveAcc.start();
        
String theOppId = (String)flowToRemoveAcc.getVariableValue('opportunityId');
System.debug('SF theOppId = ' + theOppId);

My advices:

1. Be sure that your variable removedPartId is the one you have in your flow, and it is well written. In my case, I also check the opportunityId value at the end to be sure it is well retrieved in the flow.
2. Double check the id. Does it exist?
3. Be sure your flow name is ok. FindPRC  should be the UniqueName field

If your code is fine, let's check the Flow

1. Be sure your flow type is Autolaunched Flow otherwise you cannot call it directly from code.
2. Be sure that your removedPartId variable type is Text (for Ids) and also type is Input / output

Does it work?
This was selected as the best answer
DixitSDixitS

Error is showing whille executing code from asychrous block :(

 "System.FlowException: An unhandled fault has occurred in this flow An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information."

Agustina GarciaAgustina Garcia
Do you have any other code or just the call to the flow? 

Also double check that your flow works if you click on Run button from the designer. Maybe there is something wrong in the flow itself.

Agustina
DixitSDixitS
Thanks For help @ Agustina , Now it is solved :)