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
gowtham asokan 11gowtham asokan 11 

Calling batch from trigger

Am inserting 1000 records to Task object, as per the trigger functionality it splits in 200 and inserts/updates the records. During this insertion 5 batches splits up and running concurrently this is causing some failures in batches. So i need to create list of 1000 records during insert in the trigger and call the batch apex for single time kindly help me very urgent
randheer practiserandheer practise
treat this code as Example trigger invoking batchclass.this might be helpfull to by comparing your class with this Example
Trigger:
trigger batchClass on customer__c (before insert) {
list<customer__C> c = new list<customer__C>();
for(customer__C c1:trigger.new){
 if(c1.telephone__c==null){
  BatchApex_class k = new BatchApex_class();
  database.Executebatch(k,4);
 }
}
}

BatchApexClass:
global class BatchApex_class implements database.Batchable <customer__c> {
    Global Iterable<Customer__c> start(Database.BatchableContext bc){
      list<customer__c> custom = [SELECT id,name,Address__C from Customer__C];  
      return custom;  
    }
    Global void execute(Database.BatchableContext bc, List<Customer__c> custom){
        for(customer__c c :custom){
            c.name = 'Mr11. '+c.name;
        } 
        update custom;
    }
    Global void finish(Database.BatchableContext bc)
    {
     BatchIndustry_class b  = new BatchIndustry_class();
     database.executeBatch(b,4);
    }
}