[SalesForce] Updating records via Process Builder invoked apex

We have a custom object, Option, which has apex triggers and process builder field updates. We're now introducing an Invocable apex to be called from the existing process. Two reasons why we need to do this:

  1. The new calculation is too complex for a process builder to compute
  2. The new calculation is dependent on the existing calculations performed by the process builder

Within the Invocable method, there's a query on the Option object to refetch the records from the database before proceeding with the calculation. Again, two reasons:

  1. Unlike a trigger, the process builder will NOT have all the fields for the record/records in context
  2. I need a new 'instance' of the records anyway since they ones that process builder provides are 'read-only' (I verified by trying to update the instance directly)

Now the question is, if I refetch the records via a SOQL, will they have the fields updated by the process builder actions preceding the Invocable call?

Note: When I cloned the reference passed by process builder, I was able to update the records but I'm trying to find out if pulling from the DB will have the updated fields

Best Answer

The code execution will be as follows:

  1. Process builder update action (field update)
  2. After update trigger will fire
  3. InvocableMethod

Yes, if you refetch the records via SOQL query it will give you updated records which have been modified in PB update action.

Related Topic