thank you for your time, right now I'm trying to cover as the title says a standardSetController but I'm having some difficulties, the rest of the code is covered so I don't think i need to put the rest here, the part that is missing the cover is the following:

public ApexPages.StandardSetController sageFiles {
        get {
            if (sageFiles == null) {
                sageFiles = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [Select Id, Name, DatePostedtoSage__c, AccountNumber__c, GoodsAmount__c, TransactionDate__c, PostedtoSage__c FROM SageExtract__c where PostedtoSage__c = false]));
            return sageFiles;

If you could give me some guidelines I would be very appreciated.

Even if it is irrelevant i will put the test class bellow:

 @isTest private class SageCsvFileControllerTest {

    static void test() {

        List < SageExtract__c > lstSages = new List < SageExtract__c > ();

        SageExtract__c novoSage = new SageExtract__c(
            Name = 'TESTE Sage',
            DatePostedtoSage__c = system.today(),
            AccountNumber__c = '1100',
            GoodsAmount__c = 400,
            TransactionDate__c = system.today(),
            PostedtoSage__c = false

        SageExtract__c novoSage1 = new SageExtract__c(
            Name = 'TESTE Sage1',
            DatePostedtoSage__c = system.today(),
            AccountNumber__c = '1200',
            GoodsAmount__c = 500,
            TransactionDate__c = system.today(),
            PostedtoSage__c = false
        insert lstSages;
                //Cover PageReference Method
        PageReference pageRef = Page.SageCSV;
        ApexPages.StandardSetController stc = new ApexPages.StandardSetController(lstSages);
        SageCsvFileController objCtrl = new SageCsvFileController(stc);
        PageReference objPageRef = objCtrl.newPage();


  • just call objCtrl,getsageFiles () it will call your method – Pranay Jaiswal Feb 19 '19 at 12:59
  • @PranayJaiswal that's not working, if it were so easy i would not have asked... – Nuno Carvalho Feb 19 '19 at 13:11

If it's not covered, you simply need to check the variable:

System.assertEquals(2, objCtrl.sageFiles.getRecords().size());

This line of code, posted anywhere after objCtrl is defined, should prove that there are two records (the two we created in the unit test), as well as cover the lines of code you're missing.

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.