You need to sign in to do that
Don't have an account?
Michael Clarke 36
How do I test vf page and controller extension
Hi, I have built my first vf page and controller extension and it works fine in Sandbox.
How do I create a Test class for this?
Visualforce Page:
Controller Extension Class:
How do I create a Test class for this?
Visualforce Page:
<apex:page standardController="Case" extensions="Case_ListOppSplits_Controller" lightningStylesheets="true"> <apex:pageBlock> <apex:pageBlockTable value="{!Opportunity_Splits}" var="oppSplit"> <apex:column value="{!oppSplit.Name}"/> <apex:column value="{!oppSplit.Split_Loan_Amount__c}"/> <apex:column value="{!oppSplit.Rate_Type__c}"/> <apex:column value="{!oppSplit.Repayment_Type__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Controller Extension Class:
public class Case_ListOppSplits_Controller { public Case myCase; public Case_ListOppSplits_Controller(ApexPages.StandardController stdController){ this.myCase = (Case)stdController.getRecord(); } //initialise setController and return a list of records public list<Opportunity_Split__c> getOpportunity_Splits(){ Case currentCase = [SELECT Id, Subject, Opportunity__c FROM Case WHERE Id =: ApexPages.currentPage().getParameters().get('id')]; List<Opportunity_Split__c> OppSplit = [SELECT Id, Name, Opportunity__c, Loan_Purpose__c, Loan_Type__c, Loan_Usage__c, Rate_Type__c, Repayment_Type__c, Split_Loan_Amount__c FROM Opportunity_Split__c WHERE Opportunity__c =: currentCase.Opportunity__c]; return OppSplit; } }
Can you try checking the below link as it has a similar use case test class that could help:
>> https://developer.salesforce.com/forums/?id=9060G000000Bj8MQAS
Let me know if this helps and in case if this comes handy can you please choose this as best answer so that it can be used by others in the future.
Regards,
Anutej
Thanks for the link.
I have attempted to adjust to my requirements.
I have this test code with one error: variable does not ext - OppSplit I don't fully understand what is going on here but based on the code in the link, I can't see the problem with OppSplit - the variable returned by the controller extension.