0

Im working on creating a test class for two apex classes(one is scheduled another is batch apex. The scheduled is linked to the batch apex to have it run regularly.) The issue that I am running into is in the setup() method where I need to create a dummy visualforce page and assign it to billingFormat.AcctSeed_Visualforce_PDF_Page__c (line:13). This field is a 40 character text field that references a vf page, is required, and will not take any random characters. Also I previously tried to create an emailtemplate I think since I saw that type in one of the error logs but I got a Mixed DML error on top of that.

I suppose I could use the "SeeAllData = True" route but heard that is bad practice.

Is it even possible to create a dummy visualforce page for an apex class. I have spent the last day and a half searching but only find references to visualforce controllers. Any advice or guidance would be greatly appreciated.

Bill_Creation_Test.apxc

@isTest
public class Bill_Creation_Test {
    
    @testSetup static void setup(){

        
            
        // Accounting Seed Billing Format
        List<AcctSeed__Billing_Format__c> bfList = new List<AcctSeed__Billing_Format__c>();
        AcctSeed__Billing_Format__c billingFormat = new AcctSeed__Billing_Format__c();
        billingFormat.AcctSeed__Default_Email_Template__c = 'Default Email Template';
        billingFormat.Name = 'PDF Name';
        billingFormat.AcctSeed__Visualforce_PDF_Page__c = ;
        bfList.add(billingFormat);
        insert bfList;
        
        
        
        //Account that is a blackbox customer and has inventory
        List<Account> customers = new List<Account>();
        Account bbcustomer = new Account();
        bbcustomer.Name = 'TestCustomer';
        bbcustomer.is_BB_Customer__c = True;
        bbcustomer.Has_Inventory__c = True;
        customers.add(bbcustomer);
        insert customers;
        
        
        //Accounting Period
        Date startDate = system.today();
        Date endDate = startDate.addMonths(1).addDays(-1);
        String dateFormat = 'yyyy-MM';
        Datetime yearAndMonth = Datetime.newInstance(startDate.year(), startDate.month(), startDate.day());
        String accountPeriodName = yearAndMonth.format(dateFormat);
        
        AcctSeed__Accounting_Period__c accountingPeriod = new AcctSeed__Accounting_Period__c();
        accountingPeriod.AcctSeed__Start_Date__c = startDate;
        accountingPeriod.AcctSeed__End_Date__c = endDate;
        accountingPeriod.AcctSeed__Status__c = 'Open';
        accountingPeriod.Name = accountPeriodName;
        insert accountingPeriod;
        

        
    }
    
    @isTest static void BillCreationSyncTest(){
        Blackbox_Bill_Creation_Sync test1 = new BlackBox_Bill_Creation_Sync();
        test1.execute(null);
        AcctSeed__Accounting_Period__c[] aPeriod =
            [SELECT Id
            FROM AcctSeed__Accounting_Period__c
            LIMIT 1];
        System.assert(aPeriod != null);
    }
    
    @isTest static void BillCreationTest(){
        Test.startTest();

        Blackbox_Bill_Creation test2 = new Blackbox_Bill_Creation();
        Id batchId = Database.executeBatch(test2);
        
        Test.stopTest();
        AcctSeed__Billing__c[] testBill =[
            SELECT Name
            FROM AcctSeed__Billing__c
        ];
        System.assert(testBill != null);
        
    }
}```

2
  • How is this used? You can isolate + mock parts of your logic to avoid usage of an actual VF page
    – kurunve
    Mar 11, 2021 at 14:18
  • If I understand you correctly, the original VF page is used within a managed object so I don't think there is a way for me to work around it.
    – Jebert
    Mar 11, 2021 at 14:40

1 Answer 1

2

You can create a Visualforce page outside of the test class and reference it even if you don't have (SeeAllData=True). Visualforce pages are metadata, not data.

You can reference the Visualforce Page with Page.DummyPageApiName.

UPDATE: I did a google search for your specific case, I found this page https://support.accountingseed.com/hc/en-us/articles/360015576014-Billing-Test-Class. It appears that AccountingSeed, requires that you pass in a the name of the VF page as a string, like so billingFormat.AcctSeed__Visualforce_PDF_Page__c = 'DummyPageApiName';

2
  • How would I go about doing that? Would I just use a SOQL query to get the reference ID of that dummy visualforce page?
    – Jebert
    Mar 11, 2021 at 14:38
  • I updated the answer. Mar 11, 2021 at 16:30

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.