0

Error : Error while runnig test class. This vf is getting called from a list view button on the home page of custom object.

VF Page:

<apex:page StandardController="EQ_BulkOrders__c" extensions="APTS_BulkOrderBatchNew"  action=" 
       {!StartBactJob}" recordSetVar="risks" lightningStylesheets="true"  standardStylesheets="true">

        <apex:pageMessages ></apex:pageMessages>

        </apex:page>

Controller :

public class APTS_BulkOrderBatchNew{

   public APTS_BulkOrderBatchNew(ApexPages.StandardSetController controller) {

  } 

    public PageReference StartBactJob()

  {
      Integer MaxOrdersPerBatch = 30;
      if(System.Label.APTS_OrdersPerBatch == null)
       MaxOrdersPerBatch = 30;
       else
       MaxOrdersPerBatch = Integer.valueOf(System.Label.APTS_OrdersPerBatch);

    List<EQ_BulkOrders__c> listOfBO=[select  id from EQ_BulkOrders__c  where EQ_BatchNumber__c =''];
    Integer CountBO= listOfBO.size(); 
  System.debug('*******CountBO count******'+ CountBO);
Integer NoOfBatches=CountBo/MaxOrdersPerBatch; 
System.debug('*******NoOfBatches******'+ NoOfBatches);

if(CountBO>=MaxOrdersPerBatch)
{
  for(integer i=1;i<=NoOfBatches+1;++i)
  {
      System.debug('********CountBO/NoOfBatches*****'+ i);
      //database.executeBatch(new APTS_BulkOrderCreation_Batch(CountBO/NoOfBatches>=MaxOrdersPerBatch?CountBO/NoOfBatches:math.mod(CountBo,NoOfBatches)),1);
      database.executeBatch(new APTS_BulkOrderCreation_Batch(MaxOrdersPerBatch),1);
      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm,'BulkOrder Batch has started....'));
  }
}
else 
  {
     for(integer i=1;i<=CountBO;++i)
      {
        database.executeBatch(new APTS_BulkOrderCreation_Batch(1),1);
      }
  }


 return(new PageReference('/'+Schema.SObjectType.EQ_BulkOrders__c.getKeyPrefix()+'/o'));

} }

Test Class :

@isTest

public class APTS_BulkOrderBatchNewTest {

public static testMethod void draftOrderTest() {        
    Apttus_Config2__PaymentTerm__c paymentTerm = new Apttus_Config2__PaymentTerm__c();
    paymentTerm.Name = 'Net 90 days';
    paymentTerm.Apttus_Config2__Sequence__c = 1;
    insert paymentTerm;


    Apttus_Config2__BillingPreference__c billingPreference = new Apttus_Config2__BillingPreference__c();
    billingPreference.Apttus_Config2__Active__c = true;
    billingPreference.Name  = 'EQ Preference - April';
    billingPreference.Apttus_Config2__BillingCycleStart__c = 'Period Start Date';
    billingPreference.Apttus_Config2__BillingDayOfMonth2__c = '1st of the Month';
    billingPreference.Apttus_Config2__BillingInterval__c = 'Anytime';
    billingPreference.Apttus_Config2__CalendarCycleStart__c = 'April';
    billingPreference.Apttus_Config2__InvoiceDeliveryMethod__c = 'Email';
    billingPreference.Apttus_Config2__InvoiceOutputFormat__c ='PDF';
    billingPreference.Apttus_Config2__PrefLevel__c ='Organization';
    billingPreference.Apttus_Config2__ProrationPeriodTreatment__c = 'Separate Period';
    billingPreference.Apttus_Config2__TaxLevel__c = 'Account';
    billingPreference.Apttus_Config2__Default__c = true;
    billingPreference.Apttus_Config2__AllowPaymentTermOverride__c = false;
    billingPreference.Apttus_Config2__AllowPrefOverride__c = false;
    billingPreference.Apttus_Config2__DoNotCreateInformational__c = false;
    billingPreference.Apttus_Config2__HideInformational__c = false;
    insert billingPreference;

    Apttus_Config2__LegalEntity__c legalEntity = new Apttus_Config2__LegalEntity__c();
    legalEntity.Apttus_Config2__LegalEntityName__c = 'Test Legal Entity';
    legalEntity.Apttus_Config2__IsDefault__c = true;
    insert legalEntity;


    //Insert Account
    Account account = new Account ();
    account.Name = 'TestAccount1-JPM';
    account.EQ_ClientRef__c = 'EQ146583';
    account.EQ_Legal_Entity__c = legalEntity.Id; 
    account.Apttus_Config2__BillingPreferenceId__c = billingPreference.Id;
    account.Apttus_Config2__PaymentTermId__c = paymentTerm.Id;
    insert account;

    Apttus_Config2__AccountLocation__c accountLocationSO_ST = new Apttus_Config2__AccountLocation__c();
    accountLocationSO_ST.Name = 'JPM ShipTo';
    accountLocationSO_ST.Apttus_Config2__AccountId__c = account.Id;
    accountLocationSO_ST.EQ_SourceSystem__c = 'CRM';
    accountLocationSO_ST.Apttus_Config2__Type__c = 'Ship To';
    accountLocationSO_ST.Apttus_Config2__State__c = 'Texas';
    insert accountLocationSO_ST;

    Apttus_Config2__AccountLocation__c accountLocationSO_BT = new Apttus_Config2__AccountLocation__c();
    accountLocationSO_BT.Name = 'JPM BillTo';
    accountLocationSO_BT.Apttus_Config2__AccountId__c = account.Id;
    accountLocationSO_BT.EQ_SourceSystem__c = 'CRM';
    accountLocationSO_BT.Apttus_Config2__Type__c = 'Bill To';
    accountLocationSO_BT.Apttus_Config2__State__c = 'Texas';
    insert accountLocationSO_BT;

    account.EQ_Bill_To_Account_Location_CRM__c = accountLocationSO_BT.Id;
    account.EQ_Ship_To_Account_Location_CRM__c = accountLocationSO_ST.Id;
    update account;


    //Insert Price List
    Apttus_Config2__PriceList__c pricelist = APTS_TestDataSetup.createPriceList('Test Price List');
    insert pricelist;


    List<Product2> listProduct = new list<Product2>();
    listProduct.add(APTS_TestDataSetup.createProduct('Product1', 'Products', 'Bundle'));
    listProduct.add(APTS_TestDataSetup.createProduct('Product2', 'Products', 'Standalone'));
    listProduct.add(APTS_TestDataSetup.createProduct('ProductOption', 'Products', 'Option'));
    insert listProduct;

    //create PriceListIteams
    List<Apttus_Config2__PriceListItem__c> listPLI = new List<Apttus_Config2__PriceListItem__c>();
    listPLI.add(APTS_TestDataSetup.createPriceListItem(pricelist.Id, listProduct[0].ID));
    listPLI.add(APTS_TestDataSetup.createPriceListItem(pricelist.Id, listProduct[1].Id));
    listPLI.add(APTS_TestDataSetup.createPriceListItem(pricelist.Id, listProduct[2].Id));
    insert listPLI;

    // Apttus_Config2__Order__c order = new Apttus_Config2__Order__c();
    // order.Apttus_Config2__LegalEntityId__c = legalEntity.Id;
    // order.Apttus_Config2__BillToAccountId__c = account.Id;
    // order.Apttus_Config2__ShipToAccountId__c = account.Id;
    // order.Apttus_Config2__SoldToAccountId__c = account.Id;
    // order.Apttus_Config2__Status__c = 'Draft';
    // order.Apttus_Config2__Type__c = 'New Business';
    // order.Apttus_Config2__PriceListId__c = pricelist.Id;
    // order.Apttus_Config2__PaymentTermId__c = account.Apttus_Config2__PaymentTermId__c;
    // order.Apttus_Config2__OrderDate__c = system.Now();
    // order.Apttus_Config2__OrderStartDate__c = system.Today();
    // order.Apttus_Config2__OrderEndDate__c = system.Today().addDays(30);
    // order.EQ_BillToLocationId__c = accountLocationSO_BT.Id;
    // order.EQ_ShipToLocationId__c = accountLocationSO_ST.Id;
    // order.EQ_IsLegacyRecord__c = true;
    // order.Apttus_Config2__BillingPreferenceId__c =  account.Apttus_Config2__BillingPreferenceId__c;
    // order.CurrencyIsoCode = 'USD';
    // //order.Apttus_QPConfig__ProposalId__c = null;
    // //order.Apttus_Config2__Source__c = 'Account'; 
    // insert order;

    // System.debug('Order ' + order);
    // System.debug('OrderId ' + order.Id);
    // System.debug('Order-OrderDate ' + order.Apttus_Config2__OrderDate__c);

    // order.Apttus_Config2__Source__c = 'Account';
    // update order;

    // System.debug('Order-OrderDate ' + order.Apttus_Config2__Source__c);


    EQ_BulkOrders__c objBulkOrder = new EQ_BulkOrders__c();
    objBulkOrder.EQ_Client_Ref__c = account.EQ_ClientRef__c;
    objBulkOrder.EQ_CreatedByXAE__c = true;
    objBulkOrder.EQ_Currency__c = null;
    objBulkOrder.EQ_ErrorMessage__c = '';
    objBulkOrder.EQ_LegacyData__c = true;
    objBulkOrder.EQ_LegalEntity__c = legalEntity.Id;
    objBulkOrder.EQ_Name__c = 'Test Bulk Order';
    objBulkOrder.EQ_OrderCreationError__c = '';
    objBulkOrder.EQ_OrderCreationStatus__c = 'Pending';
    objBulkOrder.EQ_Order_Date__c = system.Today();
    objBulkOrder.EQ_Order_End_Date__c = system.Today().addDays(30);
    objBulkOrder.EQ_Order_Start_Date__c = system.Today();
    objBulkOrder.EQ_Payment_Term__c = account.Apttus_Config2__PaymentTermId__c;
    objBulkOrder.EQ_PriceList__c = pricelist.Id;
    objBulkOrder.EQ_PricingCallStatus__c = 'Pending';
    objBulkOrder.EQ_ReadyForActivationDate__c = null;
    objBulkOrder.EQ_SFDCOrderId__c = null;
    objBulkOrder.EQ_BillTo__c = account.Id;
    objBulkOrder.EQ_Ship_To__c = account.Id;
    objBulkOrder.EQ_ShipToLocation__c = accountLocationSO_ST.Id;
    objBulkOrder.EQ_BillToLocation__c = accountLocationSO_BT.Id;
    objBulkOrder.EQ_Sold_To__c = account.Id;
    objBulkOrder.EQ_Source__c = 'Account';
    objBulkOrder.EQ_Status__c = 'Draft';
    objBulkOrder.EQ_StatusCustom__c = 'Draft';
    objBulkOrder.EQ_Type__c = 'New Business';
    objBulkOrder.EQ_BillingPreference__c = account.Apttus_Config2__BillingPreferenceId__c;
    insert objBulkOrder;

    EQ_BulkOrderLI__c objBulkOrderLI_Standalone = new EQ_BulkOrderLI__c();
    objBulkOrderLI_Standalone.BulkOrder__c = objBulkOrder.Id;
    objBulkOrderLI_Standalone.EQ_AddProductRequest__c = '';
    objBulkOrderLI_Standalone.EQ_AddProductStatus__c = 'Pending';
    objBulkOrderLI_Standalone.EQ_AdjustmentAmount__c = 0;
    objBulkOrderLI_Standalone.EQ_AdjustmentType__c = 'Price Override';
    objBulkOrderLI_Standalone.EQ_ConfigurationType__c = 'Standalone';
    objBulkOrderLI_Standalone.EQ_CustomDescription__c = '';        
    objBulkOrderLI_Standalone.EQ_EndDate__c = objBulkOrder.EQ_Order_End_Date__c;
    objBulkOrderLI_Standalone.EQ_AddProductResponse__c = '';
    objBulkOrderLI_Standalone.EQ_LineStatus__c = 'New';
    objBulkOrderLI_Standalone.EQ_Location__c = objBulkOrder.EQ_BillToLocation__c;
    objBulkOrderLI_Standalone.EQ_MinimumFee__c = 0;
    objBulkOrderLI_Standalone.EQ_NetPrice__c = 10;
    objBulkOrderLI_Standalone.EQ_Option__c = null;
    objBulkOrderLI_Standalone.EQ_OptionCode__c = null;
    objBulkOrderLI_Standalone.EQ_ParentBundleNumber__c = null;
    objBulkOrderLI_Standalone.EQ_PrimaryLineNumber__c = 1;
    objBulkOrderLI_Standalone.EQ_Product__c = listProduct[1].Id;
    objBulkOrderLI_Standalone.EQ_ProductCode__c = 'pcode';
    objBulkOrderLI_Standalone.EQ_Quantity__c = 1;
    objBulkOrderLI_Standalone.EQ_SellingTerm__c = 1;
    objBulkOrderLI_Standalone.EQ_StartDate__c = objBulkOrder.EQ_Order_Start_Date__c;
    insert objBulkOrderLI_Standalone;

    EQ_BulkOrderLI__c objBulkOrderLI_Bundle = new EQ_BulkOrderLI__c();
    objBulkOrderLI_Bundle.BulkOrder__c = objBulkOrder.Id;
    objBulkOrderLI_Bundle.EQ_AddProductRequest__c = '';
    objBulkOrderLI_Bundle.EQ_AddProductStatus__c = 'Pending';
    objBulkOrderLI_Bundle.EQ_AdjustmentAmount__c = 0;
    objBulkOrderLI_Bundle.EQ_AdjustmentType__c = 'Price Override';
    objBulkOrderLI_Bundle.EQ_ConfigurationType__c = 'Bundle';
    objBulkOrderLI_Bundle.EQ_CustomDescription__c = '';        
    objBulkOrderLI_Bundle.EQ_EndDate__c = objBulkOrder.EQ_Order_End_Date__c;
    objBulkOrderLI_Bundle.EQ_AddProductResponse__c = '';
    objBulkOrderLI_Bundle.EQ_LineStatus__c = 'New';
    objBulkOrderLI_Bundle.EQ_Location__c = objBulkOrder.EQ_BillToLocation__c;
    objBulkOrderLI_Bundle.EQ_MinimumFee__c = 0;
    objBulkOrderLI_Bundle.EQ_NetPrice__c = 10;
    objBulkOrderLI_Bundle.EQ_Option__c = null;
    objBulkOrderLI_Bundle.EQ_OptionCode__c = null;
    objBulkOrderLI_Bundle.EQ_ParentBundleNumber__c = null;
    objBulkOrderLI_Bundle.EQ_PrimaryLineNumber__c = 2;
    objBulkOrderLI_Bundle.EQ_Product__c = listProduct[0].Id;
    objBulkOrderLI_Bundle.EQ_ProductCode__c = 'pcode';
    objBulkOrderLI_Bundle.EQ_Quantity__c = 1;
    objBulkOrderLI_Bundle.EQ_SellingTerm__c = 1;
    objBulkOrderLI_Bundle.EQ_StartDate__c = objBulkOrder.EQ_Order_Start_Date__c;
    insert objBulkOrderLI_Bundle;

    EQ_BulkOrderLI__c objBulkOrderLI_Option = new EQ_BulkOrderLI__c();
    objBulkOrderLI_Option.BulkOrder__c = objBulkOrder.Id;
    objBulkOrderLI_Option.EQ_AddProductRequest__c = '';
    objBulkOrderLI_Option.EQ_AddProductStatus__c = 'Pending';
    objBulkOrderLI_Option.EQ_AdjustmentAmount__c = 0;
    objBulkOrderLI_Option.EQ_AdjustmentType__c = 'Price Override';
    objBulkOrderLI_Option.EQ_ConfigurationType__c = 'Option';
    objBulkOrderLI_Option.EQ_CustomDescription__c = '';        
    objBulkOrderLI_Option.EQ_EndDate__c = objBulkOrder.EQ_Order_End_Date__c;
    objBulkOrderLI_Option.EQ_AddProductResponse__c = '';
    objBulkOrderLI_Option.EQ_LineStatus__c = 'New';
    objBulkOrderLI_Option.EQ_Location__c = objBulkOrder.EQ_BillToLocation__c;
    objBulkOrderLI_Option.EQ_MinimumFee__c = 0;
    objBulkOrderLI_Option.EQ_NetPrice__c = 10;
    objBulkOrderLI_Option.EQ_Option__c = listProduct[2].Id;
    objBulkOrderLI_Option.EQ_OptionCode__c = 'pcode';
    objBulkOrderLI_Option.EQ_ParentBundleNumber__c = 2;
    objBulkOrderLI_Option.EQ_PrimaryLineNumber__c = 3;
    objBulkOrderLI_Option.EQ_Product__c = listProduct[0].Id;
    objBulkOrderLI_Option.EQ_ProductCode__c = 'pcode';
    objBulkOrderLI_Option.EQ_Quantity__c = 1;
    objBulkOrderLI_Option.EQ_SellingTerm__c = 1;
    objBulkOrderLI_Option.EQ_StartDate__c = objBulkOrder.EQ_Order_Start_Date__c;
    insert objBulkOrderLI_Option;

    Test.startTest();
    ApexPages.StandardController sc = new ApexPages.standardController(objBulkOrder);
    APTS_BulkOrderBatchNew obj = new APTS_BulkOrderBatchNew( sc );  

   // database.executeBatch(new APTS_BulkOrderCreation_Batch(1),1);
    Test.stopTest();
}

// public static testMethod void pendingOrderTest() {
//     setupTest('Pending',null);    
//     Test.startTest();
//     database.executeBatch(new APTS_BulkOrderCreation_Batch(1),1);
//     Test.stopTest();
// }

// public static testMethod void activatedOrderTest() {
//     setupTest('Activated',system.Today()); 
//     Test.startTest();
//     database.executeBatch(new APTS_BulkOrderCreation_Batch(1),1);
//     Test.stopTest();
// }

}

1

While errors from Salesforce can be very cryptic, this one is pretty easy to understand.

In the code you've provided, you only define one constructor

public APTS_BulkOrderBatchNew(ApexPages.StandardSetController controller)

It takes an ApexPages.StandardSetController
In your test code, you try to run

ApexPages.StandardController sc = new ApexPages.standardController(objBulkOrder);
APTS_BulkOrderBatchNew obj = new APTS_BulkOrderBatchNew( sc );

You're passing an ApexPages.StandardController

ApexPages.StandardController != ApexPages.StandardSetController

So you end up with an error message.

Your test needs to change so that it creates an ApexPages.StandardSetController

2
  • thanks for notifying me this miss. Everytime I was looking into StandardSetController I dint realize it is different from StandardController. I agree this should be same.
    – Suren
    Apr 9 '20 at 12:17
  • Even after making changes getting same error. ApexPages.StandardSetController sc = new ApexPages.standardSetController(objBulkOrder); APTS_BulkOrderBatchNew obj = new APTS_BulkOrderBatchNew( sc );
    – Suren
    Apr 10 '20 at 6:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.