-
How to create a test class for a controller extension
Case object needs to lookup up the related Opportunity and display the child Opportunity Splits on the case page as a visualforce page component.
Controller Extension:
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> OppSplits = [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 OppSplits;
}
}I am lost creating the test class, here is my attempt - 28% code coverage: (won't compile in current form)
@isTest
public class Case_ListOppSplits_Controller_Test {
static testMethod void testMethod1()
{
Case testCase = new Case();
testCase.Subject='Test Case';
testCase.Opportunity__c='0067F00000N8vSVQAZ';
testCase.RecordTypeId='0126D000000qSBcQAM'; //UA
testCase.Status='Assigned';
insert testCase;
Test.StartTest();
PageReference pageRef = new PageReference('https://omniwealth--dwr.my.salesforce.com/apex/Case_OpportunitySplits?id='+testCase.Id); //??instantiates the page - doesn't this run the controller?
ApexPages.StandardController sc = new ApexPages.StandardController(testCase);
Case_ListOppSplits_Controller extn = new Case_ListOppSplits_Controller(sc);
List<Case_ListOppSplits_Controller> listOppSplits = extn.OppSplits; //based on code in example
Test.StopTest();
}
}
Log In to reply.
Popular Salesforce Blogs
Dreamforce 2022 - An Overview of the Salesforce Largest Software Conference
Hello Trailblazers, are you ready to attend the most impactful Dreamforce event ever? This year will be an extra special and epic Salesforce family reunion…
Creating Reports in Salesforce: Most Important Aspects
The time has come. Your business begins to ask questions, and the data you have collected has the answers. You need the information to help…
Set Up and Manage Salesforce Communities
Introduction Communities we create works as an important way of sharing information between people who are part of our business i.e. employees, partners, and customers.…
Popular Salesforce Videos
Who Should Use SFRA and PWA? | Salesforce Commerce Cloud
Different organizations need different architecture according to their needs. Organizations who want their website built on the latest technology and modern approaches can go towards…
Mission Mangal | Build a Mars Communication Uplink | Salesforce Tutorials | Mini Project
In this video, you will learn to create a Mars Communication Uplink using Salesforce. We will create a communication system from Rovers on Mars. Interesting…
Is Trailhead enough to crack Salesforce Interview?
In this video, Shrey answered one of the most asked questions related to Salesforce Interview. Let's see how beautifully Shrey answered this Question. We hope…
Popular Salesforce Infographics
Salesforce Dreamforce: A History of Innovation
Salesforce is anything but your average technology company. From its 1-1-1 philanthropic model to the scrappy startup culture, Salesforce defies traditional logic for how a…
Top 5 ETL Tools for Salesforce Data Migration
There are plenty of ETL tools for Salesforce in the market, with varying degrees of functionality and popularity. All tools are more or less the…
How to Become a Salesforce Consultant?
Begin your Salesforce Consultant journey with Trailhead to learn about the modules offered by Salesforce to its users - admin, business users and developers to…