0

I'm trying to write a flow that automatically updates a multi-select picklist field on Contacts in response to the Opportunity's Stage being changed. I'm running into issues with the multi-select picklists. The field will have several options (let's say, "A", "B", "C", and "D") and in response to the Opportunity stage change, I need to sometimes insert one of those or sometimes remove one of those. Flow doesn't do this natively and using nested functions is a huge pain so I'm writing an Invocable Apex method. This is my first time writing Invocable methods and I'm running into issues passing variables into the method.

Invocable method called for every Contact with the same AccountID as the Opportunity

The Invocable method is called for every Contact associated with the Opportunity's Account. I want to use Apex to examine the picklist and modify accordingly. Questions:

  1. Invocable methods only accept one variable. I can use Invocable variables to split them up, but then I would have to package a) the text version of the MSP and b) the tag I would like to add as a Flow Collection, and that just feels messy. Is this the best option?
  2. OR is it possible to use the Interview class to access the current Contact in the loop from the Invocable method? Then I could pass just the wanted tag to the Invocable method, access the Contact via the Interview class, and modify as needed.
  3. I'm open to ANY other options as I really need to get this finished.
1
  • so the invocable apex needs access to both the Opportunity.StageName and the Contact (and all its fields)?
    – cropredy
    Jan 14, 2021 at 0:46

1 Answer 1

0

Once approach is instead of using an invocable method, use a trigger.

You can assign the MSP values you need to each contact record in a loop, update all the records (using 'Update Record' element) and then create a trigger that listens to those changes.

2
  • I'm confused. I'm in the loop now in the Flow, which is triggered by the Opportunity record being updated. How would I go about assigning the MSP values? Flow gives you the ability to add to an MSP field, but not remove an existing MSP value.
    – clcollier
    Jan 13, 2021 at 17:08
  • If you assign a new value to the MSP field then it overrides the existing value.
    – Json
    Jan 14, 2021 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .