+ Start a Discussion
Manish Anand 10Manish Anand 10 

I have a requirement - Need to create at max 3 opportunity records for any account in a day

I have a requirement - Need to create at max 3 opportunity records for any account in a day.
Can someone guide me on on this requirement?
RbnRbn
Hi Manish,

Here is one of the way you can approach:

Create a Roll-Up Summary field on account that counts the number of Opportunity Detail records.

You can then add a validation rule that has criteria that gives an error when the count is greater than or eqaul to 3.

The error message is a little ugly and it doesn't prevent them from actually typing in the data.

But if you want to throw an error on click of new button then you need to go for some apex coding(Over riding the new button with apex) or trigger.

Let me know if it resolves your problem 

Regards,
Rabi
Manish Anand 10Manish Anand 10
Hi Rabindra,

This is ok. But it becomes tricky, when you read second part of my query. Each day, I can create at max 3 child records. Roll up summary field will continue to add.

Thanks,
Manish.
RbnRbn
Hi Manish,

My Bad!! Okie so we have to go with the trigger in this case, because its not possible via points and click

write a before trigger on Opportunity

And have an soql query something like : [Select id from opportunity where CreatedDate =: System.TODAY() - which will tell you all those records which have been created today .

Also u can retrieve the opportunity records count which are associated to a particular account .(Again soql query)

Now an if condition which checks no.of records and no.of records created today.

If the list.size = 3 , then by making use of add.error method, throw an error.

Let me know if it resolves your problem.

Regrds,
Rabi