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
Meagan DiegelmanMeagan Diegelman 

Process Builder and Trigger Issue

I have a process builder that is creating detail records and populating a few fields on creation. I also have an after insert trigger that is firing based on one of the fields that is populated during the record creation in the process builder.  Both function perfectly independently but when a record is created through the process builder that should fire the trigger it does not.  Any ideas or resources would be greatly appreciated since I'm new to triggers?
Best Answer chosen by Meagan Diegelman
Ketankumar PatelKetankumar Patel
Process builder does not fire trigger because the order of execution

Before Trigger --> After Trigger --> Workflow field update --> Before Trigger (One Time) --> After Trigger (One Time) --> Processes.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

All Answers

Ketankumar PatelKetankumar Patel
Process builder does not fire trigger because the order of execution

Before Trigger --> After Trigger --> Workflow field update --> Before Trigger (One Time) --> After Trigger (One Time) --> Processes.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
This was selected as the best answer
Meagan DiegelmanMeagan Diegelman
Thanks!  Do you know of any workaround to have a trigger fire after the process builder finished?
Ketankumar PatelKetankumar Patel
Yes there is a way but not through Trigger. In process builder there is an Action "Apex". 
  1. You need to create apex class like below with your logic in it. You must have @InvocableMethod annotation. 
  2. In Process builder Apex Action,  You should select this class and pass your object ids in it.
public class ProcessBuilderApexClass
{
    @InvocableMethod
    public static void PerformAction(List<Id> sObjectIds)
    {
        //Your Logic......
        //You can put the logic from your trigger that you want to perform here 
    }
}
Billy PilgrimBilly Pilgrim
I think the anwer is incorrect. Once you create a record via Process Builder both before insert and after insert triggers on that record will fire
Pedro Espada Manuel AccPedro Espada Manuel Acc
Sure Billy, @Ketankumar Patel's answer is  completely incorrect. The difference between actions in Workflow and Process Builder related to creation or updating records is that Process Builder actions launch all Save Cycle (that's include fire triggers again) and Workflow just fire before/after trigger excluding things such as duplicate rules, escaltion rules ... review link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm  (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm " target="_blank) . @Meagan I don't know why is working but for additional information Debug Logs are indispensable to see what is happening under scenes
Tushar Arora 26Tushar Arora 26
Triggers execute if something is updated by process builder or a record is inserted.
Nick HoffNick Hoff
@pedro i am not sure that this is true, i am currently having issues with a process builder firing an apex trigger, i am able to get the apex trigger to fire if i manually change the field in which the trigger is set for but when i attempt to allow the process builder make the change based on other criteria it does not fire the apex trigger.
Gouse Mohiddin 4Gouse Mohiddin 4
I have Below Trigger Now I need To Cal this Trigger from Process Builder How I can Achive ?

trigger Trigget_Get_Open_Oppt on Opportunity (after insert,after update,after delete){
        
    Set<Id> Accids = New Set<Id>();  
     system.debug('@@@@@'+Accids);
    for(Opportunity op:Trigger.new)
    {
        Accids.add(op.Accountid);
    }
  for(opportunity opp : [select id,StageName from opportunity where Accountid in:Accids]) {
   
      if(opp.StageName == 'Closed')
    {
      opp.AccountId ='Closed Lost';
    }
}
    
}