0

How to create a class object in different class's method and return its object. The class is a batchClass whose object needs to be created and returned in different class.

My code so far:

public static Object createBatchObj(arg1,arg2) {
    String status = null; 
    Object batchObj = null; 
    if(arg1,arg2 condition) { batchclass1 batchObjNew = new batchclass1); }
    if(arg1,arg2 condition) { batchclass2 batchObjNew = new batchclass2(); }
    else { status = 'Wrong value entered'; } 
    return batchObj; 
}

But while using it here in a test class this error comes

--at line 29 Error: Compile Error: Method does not exist or incorrect signature: [void].start(Database.BatchableContext)

Test.startTest();
    Database.insert(accList);
    batchObj.start(batchContext);            //<------------Line 29
    batchObj.execute(batchContext,accList);
4
  • ` public static Object createBatchObj(arg1,arg2) { String status = null; Object batchObj = null; if(arg1,arg2 condition) { batchclass1 batchObjNew = new batchclass1); } if(arg1,arg2 condition) { batchclass2 batchObjNew = new batchclass2(); } else { status = 'Wrong value entered'; } return batchObj; }`
    – codeath
    Sep 2, 2014 at 14:40
  • Consider this version:)
    – codeath
    Sep 2, 2014 at 14:45
  • What is 'batchObj' defined as in your test class? Sep 2, 2014 at 15:13
  • batchObj is defined as: Object batchObj = null; batchObj = new batchclass1();
    – codeath
    Sep 3, 2014 at 4:31

0

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.