-
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
How Can Salesforce Help Your Marketing Team?
Although CRMs have traditionally been linked to sales teams, Salesforce has gone further to provide great solutions for the Marketing department. Its Marketing Cloud platform…
Salesforce Lightning Tutorials with Sample Code
Salesforce Lightning Framework is the Customer-focused UI designed to build powerful dynamic apps for mobile, web, and desktop devices. The task of a Salesforce developer…
Key Benefits of Salesforce AppExchange Development for Small Businesses
Each small business operates in different ways and has distinct requirements. They can use a certain amount of time and resources. Therefore, they'd like to…
Popular Salesforce Videos
Salesforce Customer 360 Data Manager
Salesforce Customer 360 Data Manager is a cross-cloud integration capability that allows Salesforce admins and developers to combine and reconcile customer data from their Salesforce…
What is a Salesforce PDO Partner?
Salesforce market is growing very fast these years. It is estimated that in 2021 the Salesforce ecosystem will be worth around 100 billion U.S. dollars.…
Salesforce Object Search Language: What is SOSL and when to use SOSL?
When to Use SOSL? Use SOSL when you don’t know which object or field the data resides in, and you want to: Retrieve data for…
Popular Salesforce Infographics
All About The Fourth Industrial Revolution | An Infographic
We’re in the midst of the Fourth Industrial Revolution – IoT, innovation and technology are transforming the way we work and customer expectations. Every industry…
What is Salesforce CPQ or Configure, Price, Quote – [Infographic]
Enterprises are using various CPQ tools in order to enhance their business efficiency & revenue by engaging their sales reps in doing actual sales activities…
Unlock Agile and Efficient Salesforce Testing With AI-Driven Tools
Like every industry, the world of software testing and quality assurance has also gone under massive development with the emergence of AI technology. Developers and…