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
Ridhi AgarwalRidhi Agarwal 

calling batch apex class from trigger

i have a code but its not calling my parameterised constructor. I tried printing hi in my first line of constructor and its not printing that Please guide. my trigger code is 

trigger RevenueScheduleTrigger on Revenue_Schedule__c (after insert, after update) {
         List<Revenue_Schedule__c> revs = new List<Revenue_Schedule__c>();
          for (Integer i=0;i<;i++){

                  system.debug('Rev sheds are'+revs);                   
        if(revs != null && revs.size() > 0){
            RevenueSchedulerSplitBatch sp = new RevenueSchedulerSplitBatch(revs);

and a part of my batch class is :

global class RevenueSchedulerSplitBatch implements Database.Batchable<sObject>{
    global static List<Rev_Schedule_Split__c> splits = new List<Rev_Schedule_Split__c>();
    global static List<Rev_Schedule_Split__c> toDeleteSplits = new List<Rev_Schedule_Split__c>();
    global static List<sObject> revs = new List<sObject>();

    global RevenueSchedulerSplitBatch(List<sObject> RevSched){
    revs = RevSched;
    system.debug('Revenue shed from trigger are:'+ RevSched);
    global Database.QueryLocator start(Database.BatchableContext bc){
        system.debug('Rev shed are' + revs);                                
        return Database.getQueryLocator([Select Id, Schedule_Date__c,Revenue_LC__c, Revenue_USD__c, Split_Percent_2__c, Split_Percent_3__c,Sales_Rep_1__c,Sales_Rep_2__c,Sales_Rep_3__c
                                         From Revenue_Schedule__c WHERE id IN : revs]); 
      global void execute(Database.BatchableContext bc, List<Revenue_Schedule__c> spl){
             for (Rev_Schedule_Split__c rs : [SELECT Id, Revenue_Schedule__c FROM Rev_Schedule_Split__c 
                                                     WHERE Revenue_Schedule__c IN : revs]) 

Any advise will be of great help. thanks
Himanshu ParasharHimanshu Parashar
Hi Ridhi,

Can you please check whether you are able to print revs inside trigger.

Ridhi AgarwalRidhi Agarwal
yes himanshu I am able to print inside trigger. Then i ckecked debug logs under invocation of page..der it is printing hi and revs....that means it is calling my constructor but query locator is returning 0 queries.