2

My organization uses Opportunities to generate our events $Market_Project__c. When a $Market_Project__c is created, the Opportunity triggers a time-based workflow with some tasks and notifications.

Currently, when $Market_Project__c.$Event_Cancelled is changed to true, I am responsible for searching the time-based flow queue and deleting the notifications. Within the workflow rules, the evaluation criteria dropdown boxes does not populate Market_Project__c:$fields.

My knowledge of Apex is incredibly limited, but I'm doubtful of finding a declarative fix for this issue without some data restructuring which is less preferable to a simple trigger. Is a trigger a viable option?

4
  • I'm confused. Is Market Project a child or parent of Opportunity?
    – sfdcfox
    Commented Feb 24, 2016 at 16:51
  • They are independent objects, just related. I'm guessing this is why the MP fields do not appear on the workflow rule evaluation criteria.
    – JaredT
    Commented Feb 24, 2016 at 16:52
  • But, how are they related? What makes them related? How would you know which ones to look for?
    – sfdcfox
    Commented Feb 24, 2016 at 16:54
  • Forgive me, I've been using the platform for ~8 weeks now. If I understand our architecture correctly, the MP is a child of the Opportunity, but it is possible for a MP to be linked to more than one Opportunity(?). i.imgur.com/EyxAIlM.jpg is an example of what I'm looking at
    – JaredT
    Commented Feb 24, 2016 at 17:05

1 Answer 1

0

Since Opportunity has a lookup field to the Market Project, this makes the Market Project a parent of the Opportunity. Workflow rules can't work on child elements, but all is not lost. Using a Flow and the Process Builder, you can easily do what you're trying to do automatically.

First, create a new Flow (Setup > Create > Workflows and Approvals > Flows). In this Flow, create a new SObject Collection variable for Opportunity, and create a new Variable, type Text, with the Input parameter option. Then, add a Fast Lookup that finds all opportunities by Market Project Id, and assign it to the SObject Collection. Mark this element as the Start element (the green circle/arrow icon), then add a Fast Update element that uses the SObject collection. Finally, link the first element to the second, and save this Flow as an Autolaunched flow. Activate the flow.

Next, go to Process Builder (Setup > Create > Workflow & Approvals > Process Builder), and create a new Process. First, select the Market Project object as your starting object, then choose to evaluate on each edit, and add optional criteria if you want to (e.g. Event Cancelled equals true), and then go to the condition box, and choose to always evaluate the action, then finally add an immediate action that launches your flow. Make sure you assign the Market Project's Record Id to the Input variable on the flow. Finally, activate this Process.

After all that, your edits to the Market Project will now cause the related opportunities to be updated. This, in turn, will cause the workflow rules on those opportunities to fire, and if the record no longer meets the criteria, should automatically be removed from the Time Delay queue.

Alternatively, you could have just written a trigger about five lines long that does the same thing, but you'd also have to write appropriate unit testing. Going the visual way does take longer, but requires less knowledge of coding.

3
  • Thank you very much for this! I'm in the process of implementing these, but conceptually I am not seeing the point at which anything on the opportunity will change to alter its workflow rule entry criteria. Currently: Rule Criteria (Opportunity: Opportunity Record TypeEQUALSEvent Recruitment) AND (Opportunity: Staff Contract ExecutedEQUALSTrue) AND (Opportunity: Related ProgramNOT EQUAL TO A1, B2, C3)
    – JaredT
    Commented Feb 24, 2016 at 18:26
  • I should add that we are at our maximum 500 custom field limit in Opportunities, otherwise this would likely be a much simpler procedure.
    – JaredT
    Commented Feb 24, 2016 at 19:13
  • You'll want to modify your entry criteria in that case, so it can be cancelled from the market project.
    – sfdcfox
    Commented Feb 24, 2016 at 19:50

You must log in to answer this question.

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