+ Start a Discussion
karimulla testingkarimulla testing 

i need a simple trigger that i want only ten records should store in database ..only ten per object ..

while saving 11th  record it should show an error while saving that limit had exceeded
Best Answer chosen by karimulla testing
GauravendraGauravendra
HI karimulla,

Here is trigger on account object that will not save record more than 10 records.
 
trigger limitAccount on Account (before insert) {

    Integer accLen = [SELECT count() from account];
    for(Account a : Trigger.New) {
        accLen++;
        if(accLen > 10) {
            a.name.adderror('Limit Excedded');
        }
    }
    
}
Hope this helps.

All Answers

GauravendraGauravendra
HI karimulla,

Here is trigger on account object that will not save record more than 10 records.
 
trigger limitAccount on Account (before insert) {

    Integer accLen = [SELECT count() from account];
    for(Account a : Trigger.New) {
        accLen++;
        if(accLen > 10) {
            a.name.adderror('Limit Excedded');
        }
    }
    
}
Hope this helps.
This was selected as the best answer
karimulla testingkarimulla testing
thankyou #gauravendra