• Abrar Khan 4
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have a Custom Object with a numeric field to be used as a counter. The reason for that is not important now.

I'm trying to create a Flow to update the counter for each new object I create.

I have now a Process and a Flow to achieve that. Whenever an object is inserted, the flow gather it's id and passes it as a paramter to the flow.

The flow has 3 components executing the following actions:
  1. Lookup for the object just inserted, using the id informed by the process;
  2. Lookup for any object of that type sorting on the counter field desc. That will get the max value;
  3. Increments the value and update the newly inserted recorde with that counter.
That flow is working as expected when I insert only one record. Because Salesforce bulkify the execution of queries in flows, when I insert more than one object in the same transaction, it groups the queries and run them all at once. That means that it will select the max counter once and increment the same value by 1 for all the new objects I'm inserting.

As an example, if the current max counter for the object is 4 and I insert 10 new objects, all the new objects will have the same counter 5, instead of 5 through 14.

Is there any way I can have a static variable there shared accross all flow instances in that transaction?