1

So I've created a batch class, did a query, and stored the results into a map. Now I know that you can pass values from one batch to another with cascading batch calls and database.stateful, but is there a way to invoke the batch value through a normal Apex Class? Any help would be appreciated.

Edit: Here is the code for the apex batch class that populates the map. I need to somehow pass the map to another apex class and not using a cascading batch like I'm doing right now.

private String query;
public Map<Id, Id> agreementMap;
public Map<Id, Id> hierarchyMap = new Map<Id, Id>();
public List<AgreementHierarchy__c> hierarchyList = new List<AgreementHierarchy__c>();
public AgreementHierarchySupport support = new AgreementHierarchySupport();
public AgreementBatch(Map<Id, Id> agreement){
    agreementMap = agreement;
    query ='SELECT Id,leaf__c, parent__c FROM AgreementHierarchy__c';
}
public Database.querylocator start(Database.BatchableContext BC){
    //query the Agreement Hierarchy for the list to be passed on to the next batch
        return Database.getQueryLocator(query);
        }


    public void execute(Database.BatchableContext BC, List<sObject> hierarchy){
            hierarchyList = hierarchy;
            hierarchyMap = support.populateHierarchy(hierarchyList);

    }
    public void finish(Database.BatchableContext BC) {


        HierarchyBatch hier = new HierarchyBatch(agreementMap, hierarchyMap);
        Database.executeBatch(hier);
    }
  • Please include some code. – Adrian Larson Sep 29 '14 at 16:54
  • Of course, edited my post – user3724260 Sep 29 '14 at 17:30
  • 1
    Can't you store the results of your batch class in a record or custom setting? – Phil B Sep 29 '14 at 17:30
  • I thought of doing so at first, but unfortunately we are not allowed to store the data in a record – user3724260 Sep 29 '14 at 17:37
  • 2
    What exactly do you mean by "another apex class"? You can instantiate any apex class from the finish, it doesn't have to be another batch. You can also call another static function in some utility class. What exactly are you trying to do? – rael_kid Sep 29 '14 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.