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
Angel30Angel30 

An account can have only one oppty record created per day.

Hi All,

I have a scenario where I need to have an account to havev only one opportunity created per day.
Can anybody provide me with the best configuration solution for this.
Raj VakatiRaj Vakati
You need to create a trigger on Opportunity on before insert ,, 

WOKRFLOW , PROCESS BUILDER AND ROLLUPSUMMERY will not works
Selva Ramesh 4Selva Ramesh 4
Hi,

Try the below code

trigger oppo on Opportunity(before insert) {
    if (Trigger.isBefore && Trigger.isInsert) {
        List<Id> positions_ids = new List<Id>();

        // get the positions ids
        for(Opportunity j : Trigger.new) {
            positions_ids.add(j.AccountId);
        }

        // query all job postings for those positions
        List<Opportunity> other_jobs = [SELECT Id, CreatedDate, CreatedById FROM Opportunity WHERE Opportunity.AccountId IN :positions_ids];

        for (Opportunity j : Trigger.new) {
            for (Opportunity existent_record : other_jobs) {
                // check if we are comparing two records for the same position
                // if the created date for the existing record equals the current date
                // (that is, the insertion date for the record on Trigger.new), then 
                // we can send that error to the user.
                Date existent_record_created_date = existent_record.CreatedDate.date();

                    if (existent_record_created_date == Date.today()) {
                        j.addError('Cannot create opportunity because there\'s another one created on this date.');
                    }
                }
            }
        }
    }

Thanks,
Selva
SPT