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
Syed Abid ShahSyed Abid Shah 

How to restrict users from creating a opportunity more than 1 person from an account object

Hi There,

I would like to know is there any possibility to restrict users from creating more than a single opportunity per day by per person on Acount object?

Thanks
Syed
<Saket><Saket>
Hi Syed,

Yes you can do this by trigger Let me know if you want the code for it.

Thanks 
Saket Sharma
Deeprao18Deeprao18
Not sure why the restriction but yes it is possible
Syed Abid ShahSyed Abid Shah
Hi Saket,

Please share me the Code?

Thanks
Syed
Saurabh TyagiSaurabh Tyagi
Hi,

You can Use this piece of code
List<Opportunity> my_list = new List<Opportunity>();
date d=date.today();   

my_list = [Select Id, Name, CreatedDate, AccountId From Opportunity where CreatedDate =:d]; 

if(my_list.size() > 0){
//throw your validation error   
}
else
{
    insert my_list;
}
If it helps you mark it solved.
Regard,
Saurabh
 
RahulRahul
trigger Avoidcreating2opp on Opportunity (before insert,before update) {

list<opportunity> opp = [SELECT id, name FROM opportunity WHERE createddate = TODAY];

  for(opportunity o :trigger.new){
      if(o.Accountid != null){
      if(opp.size()> 0){
        o.addError('You can only create one opportunity today');
                       }
                }
          }
  }