You need to sign in to do that
Don't have an account?

Test class to display opp list
Can anyone provide Test class for following use Case.
Consider all positive negative and bulk test case
Use case ::
Collection of Closed Won Opportunities
1. I have created a custom quota object
2. Create a VF page to display all the Closed won opportunities in the org Only if
1)The opportunitys cloased date lies between start and end date of quota
2)The User which is dispalyed in the assed to user should be the same as the owner
3) The record type is BDM
I have written the below test class for the same. I do not know how to write the logic can anyone help me with the same
Apex class
public with sharing class listopponquota {
public list<Opportunity> oppList{get;set;}
public listopponquota()
{
String selectedVal ='';
oppList = new list<Opportunity>();
oppList();
}
public pageReference oppList() {
Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
system.debug('Id-->'+qId);
List<quota__c> quotaList1 = new List<quota__c>();
List<Opportunity> oppList1 = new List<Opportunity>();
quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c, OwnerId from quota__c where Id =: qId Limit 1];
oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
system.debug('quotaList1-->'+quotaList1);
if(quotaList1.size() > 0){
for(quota__c q : quotaList1){
for(Opportunity opp : oppList1){
system.debug('closedDate-->'+opp.CloseDate);
if(opp.CloseDate >= q.Start_Date__c && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
oppList.add(opp);
}
}
}
}
system.debug('oppList-->'+oppList);
return null;
}
}
Vf page
<apex:page controller="listopponquota" lightningStylesheets="true" >
<apex:form >
<apex:pageBlock rendered="true" >
<apex:pageBlockTable value="{!oppList}" var="v">
<apex:column value="{!v.OwnerId}"/>
<apex:column headerValue="Opportunity Name">
<apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
</apex:column>
<apex:column value="{!v.CloseDate}"/>
<apex:column value="{!v.StageName}"/>
<apex:column value="{!v.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Test class
@isTest
private class testclassquotaVfpage{
static testMethod void listopponquota(){
Quota__c op = new Quota__c ();
op.Name = 'test_shruthi';
op.Start_Date__c = Date.newInstance(2020,02,06);
op.End_Date__c = Date.newInstance(2020,02,19);
insert op;
}
}
Opportunity opp = new Opportunity(Name='test opp', StageName='stage', Probability = 95, CloseDate=system.today());
Opportunity opp = new Opportunity();
opp.Name = 'test_shruthi';
opp.type = 'New Customer';
opp.CloseDate = system.today();
opp.StageName ='Closed Won';
// add all required fields here
insert opp;
Database.executeBatch(new ContactWithClosedWonOpportunities());
Test.stopTest();
}
}
Consider all positive negative and bulk test case
Use case ::
Collection of Closed Won Opportunities
1. I have created a custom quota object
2. Create a VF page to display all the Closed won opportunities in the org Only if
1)The opportunitys cloased date lies between start and end date of quota
2)The User which is dispalyed in the assed to user should be the same as the owner
3) The record type is BDM
I have written the below test class for the same. I do not know how to write the logic can anyone help me with the same
Apex class
public with sharing class listopponquota {
public list<Opportunity> oppList{get;set;}
public listopponquota()
{
String selectedVal ='';
oppList = new list<Opportunity>();
oppList();
}
public pageReference oppList() {
Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
system.debug('Id-->'+qId);
List<quota__c> quotaList1 = new List<quota__c>();
List<Opportunity> oppList1 = new List<Opportunity>();
quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c, OwnerId from quota__c where Id =: qId Limit 1];
oppList1 = [Select Id, Name, CloseDate, StageName,OwnerId,Amount From Opportunity where StageName = 'Closed Won'];
system.debug('quotaList1-->'+quotaList1);
if(quotaList1.size() > 0){
for(quota__c q : quotaList1){
for(Opportunity opp : oppList1){
system.debug('closedDate-->'+opp.CloseDate);
if(opp.CloseDate >= q.Start_Date__c && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId){
oppList.add(opp);
}
}
}
}
system.debug('oppList-->'+oppList);
return null;
}
}
Vf page
<apex:page controller="listopponquota" lightningStylesheets="true" >
<apex:form >
<apex:pageBlock rendered="true" >
<apex:pageBlockTable value="{!oppList}" var="v">
<apex:column value="{!v.OwnerId}"/>
<apex:column headerValue="Opportunity Name">
<apex:outputlink value="/{!v.Id}">{!v.Name}</apex:outputlink>
</apex:column>
<apex:column value="{!v.CloseDate}"/>
<apex:column value="{!v.StageName}"/>
<apex:column value="{!v.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Test class
@isTest
private class testclassquotaVfpage{
static testMethod void listopponquota(){
Quota__c op = new Quota__c ();
op.Name = 'test_shruthi';
op.Start_Date__c = Date.newInstance(2020,02,06);
op.End_Date__c = Date.newInstance(2020,02,19);
insert op;
}
}
Opportunity opp = new Opportunity(Name='test opp', StageName='stage', Probability = 95, CloseDate=system.today());
Opportunity opp = new Opportunity();
opp.Name = 'test_shruthi';
opp.type = 'New Customer';
opp.CloseDate = system.today();
opp.StageName ='Closed Won';
// add all required fields here
insert opp;
Database.executeBatch(new ContactWithClosedWonOpportunities());
Test.stopTest();
}
}
You are getting this because you are closing the class and method with braces before it ends.Try by removing braces in 14,15 line.
Try this code
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards