Skip to main content
Mathias Krüger (adesso SE) a posé une question dans #Apex
Hello,

i need some help regarding my apex controller for my visual force page.

I got problems to get my filter into the test class. It is a custom ListView Button on the Opportunity Object.

 

<apex:page standardController="Opportunity" extensions="NPCT_createTaxReceiptVFCtrl" recordSetVar="opportunities" lightningStylesheets="true">

<p style="font-size:15px;">You are about to create Tax-Receipt for <b>all</b> donations which are selected. Proceed?</p>

<apex:form >

<apex:commandButton action="/lightning/o/Opportunity/list?filterName={!filterId}" value="No" />

<apex:commandButton action="{!createTaxReceipt}" value="Yes" />

</apex:form>

</apex:page>

Controller:

public with sharing class NPCT_createTaxReceiptVFCtrl {

public String filterId { get; set; }

public List<Opportunity> selOppList;

public NPCT_createTaxReceiptVFCtrl(ApexPages.StandardSetController controller){

this.filterId = controller.getFilterId();

selOppList = controller.getSelected();

}

public PageReference createTaxReceipt() {

for (Opportunity opp : selOppList) {

Tax_Receipt__c tax = new Tax_Receipt__c();

tax.Tax_Receipt_Type__c = NPCT_Constants.TAX_RECEIPT_INDICATOR_EINZEL_ZWB;

//tax.CurrencyIsoCode = EUR;

insert tax;

opp.Tax_Receipt_Ref__c = tax.id;

}

if (selOppList != NULL) {

Database.update(selOppList, true);

}

return new PageReference('/lightning/o/Opportunity/list?filterName='+filterId);

}

}

 
3 réponses
  1. 2 sept. 2020, 12:40
    Hi Mathias,

    Just did some small updates in the test class. Please find the updated class below:

    @isTest

    public class NPCT_createTaxReceiptVFCtrlTest {

    static testMethod void mainTest() {

    Opportunity testOpp = new Opportunity();

    testOpp.Name = 'Test Opp';

    testOpp.CloseDate = Date.today().addDays(30);

    //Enter other required fields here

    insert testOpp;

    List<Opportunity> testOppList = new List<Opportunity>();

    testOppList.add(testOpp);

    //Replace yourPageName with the name of your VF page

    PageReference pageRef = Page.yourPageName;

    Test.setCurrentPage(pageRef);

    pageRef.getParameters().put('id',testOpp.id);

    ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(testOppList);

    stdSetController.setSelected(testOppList);

    NPCT_createTaxReceiptVFCtrl objTest = new NPCT_createTaxReceiptVFCtrl(stdSetController);

    Test.startTest();

    objTest.createTaxReceipt();

    Test.stopTest();

    }

    }

    Let me know if there is any other issue.

    Thanks,

    Abhishek Bansal.​​​​​​​
0/9000