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
Mohammad Rafi 5Mohammad Rafi 5 

how to create 10 account using trigger

Gustavo BertolinoGustavo Bertolino

First you have to define what kind of event fires the trigger, when this event happens, and on which sObject the trigger takes its action. So basically your trigger should have the following design. The code is composed by the trigger and the class which contains the static method used by the trigger, as follows. Notice that it is just a paradigm and, thus, something only schematic.

trigger TrgCreateAccounts on sObject (before event) {
    LIST<Id> listOfObjects = new LIST<Id>();
    
    for (sObject obj : Trigger.New) {
        if (sObject.Attribute == 'Some Record') {
            listOfObjects.add(obj.Id);
        }
    }
    
    if (listOfObjects.size() > 0) {
        DoSomething.createAccounts(listOfObjects);
    }
}

public class DoSomething {
    public static void createAccounts (List<Id> sObjectsId) {
        LIST<sObject> listToDoSomething = [SELECT Id FROM sObjects WHERE objId IN: sObjectsId];
        Integer count = 0;
        
        for (sObject obj : listToDoSomething) {
            while (count < 10) {
                Account account = new Account();
                count++;
            }
        }
    }
}