You need to sign in to do that
Don't have an account?

Hi Guys, I want to write a trigger to restrict bankers to create opportunities worth more than 10000 dollars in a day.
Hi Guys, I want to write a trigger to restrict bankers to create opportunities worth more than 10000 dollars in a single day.
Initially get a list of all the Opportuities inserted today with amount > 10,000 $. Finally throw an error if list size is greater than 1
code to restrict users to not generate opportunity worth more than 10000 -
public class OppAmountRestriction_Class {
public static void restrictAmount(List<Opportunity> oppNew)
{
Decimal sumAmount=0;
List<Opportunity> oppOld = new List<Opportunity>();
oppOld = [Select Id,Name ,Amount from Opportunity where CreatedDate=today];
if(oppOld.size()>0)
{
for(Opportunity op : oppOld)
{
if(op.Amount!=null)
{
sumAmount += op.Amount;
}
}
}
if(oppNew.size()>0)
{
for(Opportunity op : oppNew)
{
if(op.Amount!=null)
{
sumAmount += op.Amount;
}
System.debug('sumAmount ----' + sumAmount);
if(sumAmount > 10000)
{
op.addError('opportunities worth more than 10000 dollars in a single day Exceed');
}
}
}
}
}
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks,
Ajay Dubedi