+ Start a Discussion
sai krishna 267sai krishna 267 

hi friends give me code to restrict the code for per we can able to create 15 Accounts morethan that it will be showing an error u daily limit exceeded can anybody give code

Suraj TripathiSuraj Tripathi
Hi Sai,

Try this trigger

Trigger-
trigger test on Account (before insert) {

    if(trigger.isBefore&& trigger.isInsert){
        daily15limit.m2test(trigger.new);
    }
}

Handler Class-
public with sharing class daily15limit {
    public static void m2test(list<Account> Acclist){
        
        List<Account> accOld = [select id from Account where CreatedDate = TODAY];
        system.debug('accOld--------->>>>'+accOld);
        system.debug('accOld.size()----------'+accOld.size());
        
        for(Account acc : Acclist) {
            if(accOld.size()>15)
            {
                acc.addError('Daily Limit Exceeded');
            }
        }
        
    }
    
}

If it helps you mark this best.

Regards
Suraj​