What is the difference between Call and Branch in an activity ?

An activity often needs to run another activity. Pega gives you two ways to do it, and the difference is simple but easy to forget under interview pressure: Call comes back, Branch does not.

Call

The Call method runs another activity and then returns control to the step after the call. It works like calling a function. Any steps that follow the Call step still run.

Branch

The Branch method hands over to another activity found through rule resolution and never returns. The original activity pauses, the branched activity runs, and when it finishes, the original one ends too. Any steps after the Branch step are skipped.

Comparison

CallBranch
Control after the target activity finishesReturns to the next stepDoes not return; the calling activity ends
Steps after itRun normallyNever run
Feels likeA function callA one-way jump to another activity
Typical useReuse logic, then carry onLast step, hand the rest of the work to another activity

A worked example

Suppose a bank activity ProcessTransfer has these steps:

  1. Call ValidateAccounts
  2. Call PostToLedger
  3. Branch to SendConfirmation
  4. Property-Set .Status = Done

Steps 1 and 2 return, so step 3 runs. Step 3 branches to SendConfirmation. When that activity ends, ProcessTransfer also ends, so step 4 never runs and the status stays unchanged. That is why a Branch is usually the last step of an activity.

Related ways to stop an activity

  • Exit-Activity ends the current activity and returns to the caller.
  • Activity-End ends the current activity and every activity that called it.

See our post on Activity-End and Exit-Activity for the difference.

Interview tip

Answer with one contrast: "Call returns to the caller, Branch does not." Then say Branch is used as a final hand-off and that steps after it are skipped. Browse the Activity label for more.

No comments:

Post a Comment