• alexMette
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello, I am trying to set up a rule that will prevent an opportunity from being changed to "Closed Won" unless it has a related Contract with a status of "Executed".

Our org has a custom contract object with a lookup to opportunity. 

We also have a process builder in place that fires when a contract is executed and automatically updates the related opportunity status to closed-won and updates the close date.

The reason for this is that we want to the opportunity to be closed as a result of its related contract being executed, and prevent it from being executed by sales people.

I created an Apex Class that is triggered on opportunity before update. It checks if the opportunity has a related contract and if the status of the contract is not "Executed", it throws an error. This works fine so far.

However, with the custom validation rule in place, the process builder cannot update the opportunity, so the whole transaction fails, and the contract can't be updated to executed.

As I understand it, this is because the contract hasn't been changed in the database until the whole process finishes.

I am new to Apex and development in general. Is there a way to access the value of the contract that is stored in memory in my opportunity trigger/class? Or, perhaps to create an exception to my rule that can be bypassed if the record update is triggered by a flow?

I'm definitely open to other solutions as well - but I'm curious if I've hit a limitation in trying to refer to a value of a record in memory vs. in the database that is not part of my trigger.
Dear Salesforce Gods,

Hear my prayer! My goal is to sync Outlook with a highly customized calendar in Salesforce that shows custom object records (rather than tasks, events, etc.).

So far, I have identified two possible methods of accomplishing my holy mission:
(1) Purchase an expensive 3rd Party app (LinkPoint360, Zyn, etc.)
(2) Use a trigger / workflow to create a "twin" Event record matched against every custom object record. Then use Salesforce to Outlook based on the Event records.

I kneel down and beg for guidance! Which is likely to be the better choice? Are there pitfalls or limitations I'm not aware of with option #2 that my push me toward option #1?

Or is there a different and holier path I may yet trod upon?


Thanks,
Zachary Alexander