-
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
Salesforce URL Hacking Button for Lightning Experience
The Salesforce Lightning URL Hack is a strategy for making an extraordinary hyperlink or content and uncovering it by means of catch or recipe field.…
What is Salesforce CMS: A Practical Guide
A hybrid content management system (CMS), Salesforce CMS enables you to generate, modify, arrange, and manage digital material from a single location. Publish content to channels like…
Play Around Salesforce Batch Apex And Schedule Apex
Batch Apex Batch Apex classes are beneficial if the task is something to run large jobs like thousands or millions which is exceeded than normal…
Popular Salesforce Videos
Creating a Roll-up Using DLRS | Salesforce Tutorial Video
In certain situations, an object does not support a roll-up or the relation is not permitted. Learn how to make it possible by using the…
How to Deactivate Salesforce Users
In this video, we'll show you how to Deactivate Salesforce Users. In Salesforce, you cannot delete users outright, as other references to the user may…
Get Ready for a More Connected Partner Experience | Salesforce Partners
Your destination for a connected partner experience is the Partner Community. Get Ready For an Enhanced and Personalized Experience. Watch this video and learn more…
Popular Salesforce Infographics
The Salesforce Lightning Platform for Employee Engagement: Key Findings
Salesforce provides a system of engagement across the entire employee lifecycle that enables organizations to connect multiple back-end systems of record with one system of…
See Why Salesforce Goes All In on Pro Bono
Salesforce Pro Bono Program aims to match nonprofits and higher education institutions with Salesforce professionals to maximize their Salesforce implementation and transform their organization. Scroll…
Salesforce vs. MS Dynamics 365 - Which is Best For You?
Two of the most popular options are Salesforce and MS Dynamics 365. And while every business has different priorities, there are some features, like user…