function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
benderguybenderguy 

workflow execution order question - trying to count campaign membership

I want to have a lead field that counts the number of specific types of campaigns that someone is in.  We can't create a rollup from campaign member to lead, but since I import the campaign results (including lead information) from a file every time I could do something with workflow.  I can't import a number to a field and have it just automatically added to whatever value might already be there, so here's my thought:

 

  • create two number fields on the lead: "campaign count" & "count control"
  • create a workflow rule which executes whenever "count control" is changed. I will import a number into this field whenever I want to add (or subtract) to "campaign count"
  • workflow contains two field update actions
  • the first adds the number in "count control" to the number in "campaign count" (updating "campaign count")
  • the second deletes the value that is in "count control".  this is so that next time I update this field i know that the value will be different/changed and the workflow rule will trigger each time, and so that I don't have to do two separate manual updates (one to populate the value and another to clear it later)

However, we supposedly cannot control the order of execution of workflow rules.  So, my question is, can I be sure that the number I insert into "count control" will always be used by the first field update?  In other words, is there a chance that the second rule will clear out the value from "count control" before the first rule tries to use it?  Salesforce doesn't seem to publish any information about how workflow rules are executed except that we can't control it.    Yes, I supposed this could be done by an apex trigger, but I figured this is such a nice solution that I'd see if anyone has a thought as to the reliability of this solution (or a better one!).

Ispita_NavatarIspita_Navatar

With workflow can add multiple update actions as you have pointed , but there is no sureity about the order of execution, as we have is things like assignment rule where we can provide the priority of evaluation of a criterion or subsequent action taken.

My suggestion is that you accomplish your requirement via a trigger on "Campaign Member"  whenever a new member is added you can increment the count in the corresponding lead record.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

jkucerajkucera

You need code to do cross object counts like this.  Check out this package, which has almost exactly what you're looking to do:

 

https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t30000000jDgR