2

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

  • Is your invocable operation is Synchronous or async? – Santanu Boral Jul 20 '16 at 21:59
  • It is sync. Can it be async? I believe an Invocable cannot have any other annotation – Vid L Jul 20 '16 at 22:01
  • It can be async and call future method also, which not relevant here – Santanu Boral Jul 20 '16 at 22:11
1

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.

  • The invocable method is called as an immediate action in the same Action box as the field update. Will a trigger run happen in between? That means, if I have multiple field updates, each of them makes the trigger run individually? – Vid L Jul 20 '16 at 23:35
  • For each update After trigger will be fired. – Santanu Boral Jul 21 '16 at 0:25
  • 1
    Keep in mind that changes are coming to the Process Builder, so an interested party might want to keep in touch with their success manager/account executive/etc. – sfdcfox Jul 21 '16 at 4:15
  • @LVS can you close this question if you got your ans – Santanu Boral Jul 21 '16 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.