You need to sign in to do that
Don't have an account?
Mario C
Test class for simple component controller class
Hi all,
I need to write a test class for a simple LEX component which I built, but I am struggling to understand how to write it. Can you please help me?
I need to write a test class for a simple LEX component which I built, but I am struggling to understand how to write it. Can you please help me?
public class MyOLIController { @AuraEnabled public static List<OpportunityLineItem> getProduct(List<Id> opportunityIds){ Case cs = [Select Enquiry__c from Case where Id=:opportunityIds]; List<OpportunityLineItem> productList = [SELECT Id, Property__c, OpportunityId, Start_Date_Time__c,End_Date_Time__c,Status__c FROM OpportunityLineItem WHERE OpportunityId=:cs.Enquiry__c AND (Status__c='confirmed' OR Status__c='pending' OR Status__c='booked' OR Status__c='stayed')]; return productList; } }
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the controller to access (in this case it looks like Case ,Opportunity and OpportunityLineItem)
- Instantiate the controller -
- Execute a method/methods
- Verify the behaviour with asserts.
Smaple test class for you
NOTE:- Look like some issue in code as well , How opportunityIds can be equals to Case ID ?
Case cs = [Select Enquiry__c from Case where Id=:opportunityIds];
Let us know if this will help you
Here is my code:
NOTE:- Look like some issue in code as well , How opportunityIds can be equals to Case ID ?
Case cs = [Select Enquiry__c from Case where Id=:opportunityIds];
Please change the query filter