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
Ryan GreeneRyan Greene 

Process Builder invoke Apex

I continue to receive error messages when trying to invoke Apex when a record is created. My Lead object has a related object called Additional Owners which are basically additional Contacts, so when the Lead is Converted I have a Trigger which takes the Additional Owners and creates Contact Records for them. Then I have an invocable method which sends PDFs to the newly created Contact. The invocable method is run from a Process Builder which runs when that new Contact is created. Each time I test converting a Lead Additional Owner, I recieve the error "Error:Apex trigger ContactfrmAO caused an unexpected exception, contact your administrator: ContactfrmAO: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3013F00000005Bx. Flow error messages: 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. Contact your administrator for help.: []: Trigger.ContactfrmAO: line 17, column 1"

The trigger ContactfrmAO is the trigger to create a Contact from the Additional Owner object. Line 17 is the insert of the Contact. The Flow error is for the Process Builder invoking the Apex.

It seems I am trying to do too many funcitons all at once. Any thoughts on how to make this work?
Alain CabonAlain Cabon
Hi Ryan,

Very technical (tricky) error. You will travel to the depths of Salesforce. 

Did you use the Workbench?   https://workbench.developerforce.com/login.php

You just have 3013F00000005Bx (ID=15 char, the three first figures identify the object)

30124000000PcNDAA0 : ID = 18 chars, same object 301 

300 = InteractionDefinition - Visual Workflow or Flow
301 = InteractionDefinitionVersion
http://salesforcelearn.blogspot.fr/2015/01/list-of-key-prefixes-in-salesforce.html

Help: Record couldn't be saved because it failed to trigger a flow.
  • Capture debug logs, (make sure to set debug level as FINEST for workflow) Sometimes the debug log will tell you exactly which element of the Flow is failing and why is it failing.
  • Use debug screen where you can display Request and Response details,
  • press Ctrl + Shift + M (on a windows PC) or command + shift + M (on Mac) inside the flow designer.
  • Use Workbench REST Explorer to capture more details about process/flow metadata.
1. Get the version Id from the error message
2. Login to Workbench
3. Go to Utilities > REST Explorer >> Perform a GET 
4. Add the following to the URI field and change the Id with the FlowId you are investigating /services/data/v36.0/tooling/sobjects/flow/30124000000PcNDAA0  [NOTE: v36.0 refers to the API version and as new tooling API features are released, version may need changing] 
5. Click Execute
6. Open the 'attributes' folder
7. Check the 'ProcessType', if the value is 'Flow' then this is a normal flow, if the value is 'Workflow', this is a Process. Here you can also see the MasterLabel, which should provide you with the name of the flow/process.
8. Explore the Flow Metadata tree to see what a specific element is doing, this is more useful when it's a Process Builder Flow since the error email and other error messages sometime refer to the auto-generated name like myRule1_1. 

https://help.salesforce.com/articleView?id=000239860&type=1