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
André JohnssonAndré Johnsson 

Restrict to maximum 1 open opportunity of specific record type per account?

Hi,

We have a use case where we would like to restrict the possibility of creating more than one open opportunity of a certain record type on an account. So for example: let's say we have a record type called New Sale, and one record type called Upsell. It should then only be possibly to create a single open New Sale opportunity. If there's an open New Sale opportunity a new one can not be created. However, if there's an old New Sale opportunity that's closed, then a new New Sale opportunity *can* be created. Meanwhile, the Upsell opportunity should not be affected by any of this, and multiple Upsell opportunities should always be able to be created.

Is this possible to do? If yes, would it have to be done in Apex, or could a flow be built for this?
Best Answer chosen by André Johnsson
Shubham Jain 338Shubham Jain 338
Hi,

It can be done using flow as well.
Whenever the record is inserted with that record type, get the records of the opportunity of that record type and with status not closed(You will always get either zero or one record). If the list size is greater than 1 then throw an error.


Please mark this as the best answer if it helps

Thanks
Shubham Jain