You need to sign in to do that
Don't have an account?
Writing a test class
How to write a test class for below class. The test class should work for the bulk scenario also. Please help me.
public with sharing class CloneOpportunityUtil {
public static void cloneOpportunities(List<Opportunity> oppList) {
List<IBX_Lines__c> newIBXLines = new List<IBX_Lines__c>();
Set<Id> cloneOppIds = new Set<Id>();
Map<Id,Id> cloneOppToNewOppIdMap = new Map<Id,Id>();
Map<Id,List<IBX_Lines__c>> oppIdIBXListMap = new Map<Id,List<IBX_Lines__c>>();
List<IBX_Lines__c> listIBX = null;
for(Opportunity tempOpp : oppList) {
if(tempOpp.Clone_Opportunity_ID__c != null) {
cloneOppIds.add(tempOpp.Clone_Opportunity_ID__c);
cloneOppToNewOppIdMap.put(tempOpp.Clone_Opportunity_ID__c,tempOpp.Id);
}
}
if(cloneOppIds.size() > 0) {
List<IBX_Lines__c> listIBXLines = [Select IBX_Name__c,Adjustment_Type__c,Opportunity__c,Competitors__c,Forecast_MRR__c,Forecast_NRR__c,Forecast_Status__c,Lead_Source__c,Line_Type__c,Primary_Campaign_Source__c,Cross_Region_Lead_Source__c from IBX_Lines__c where Opportunity__c IN :cloneOppIds and Forecast_Status__c = 'Slipped'];
for(IBX_Lines__c tempIBX : listIBXLines) {
if(oppIdIBXListMap.keySet().contains(tempIBX.Opportunity__c)) {
oppIdIBXListMap.get(tempIBX.Opportunity__c).add(tempIBX);
} else {
listIBX = new List<IBX_Lines__c>();
listIBX.add(tempIBX);
oppIdIBXListMap.put(tempIBX.Opportunity__c,listIBX);
}
}
}
IBX_Lines__c insertIBX = null;
for(Id tempId : cloneOppToNewOppIdMap.keySet()) {
if(oppIdIBXListMap.get(tempId).size() > 0) {
for(IBX_Lines__c tempIBX : oppIdIBXListMap.get(tempId)) {
insertIBX = new IBX_Lines__c();
insertIBX.Opportunity__c = cloneOppToNewOppIdMap.get(tempId);
insertIBX.IBX_Name__c = tempIBX.IBX_Name__c;
insertIBX.Adjustment_Type__c =tempIBX.Adjustment_Type__c;
insertIBX.Competitors__c = tempIBX.Competitors__c;
insertIBX.Forecast_MRR__c = tempIBX.Forecast_MRR__c;
insertIBX.Forecast_NRR__c = tempIBX.Forecast_NRR__c;
insertIBX.Forecast_Status__c = 'New/Active';
insertIBX.Lead_Source__c = tempIBX.Lead_Source__c;
insertIBX.Line_Type__c = tempIBX.Line_Type__c;
insertIBX.Cross_Region_Lead_Source__c = tempIBX.Cross_Region_Lead_Source__c;
insertIBX.Primary_Campaign_Source__c = tempIBX.Primary_Campaign_Source__c;
newIBXLines.add(insertIBX);
}
}
}
if(newIBXLines.size() > 0)
insert newIBXLines;
}
}
Pls Help me anyone..
Go through this documentation for test class basics,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
Hi,
@isTest
Public class CloneOpportunityUtil_Test{
static testmethod void CloneOpportunityUtil_Test(){
here create opportunity and insert it.
and also create IBX_Lines__c and insert it according to the where condition u mentioned in class
CloneOpportunityUtil opp= new CloneOpportunityUtil();
}}
Regards,
Rajesh.
Please visit the link below to understand :
- When to write Apex Test Class ?
- Which factors to be tested while writing Test class ?
- How to use @isTest Annotation in salesforce ?
- How to write apex Test Class ?
https://www.salesforcekid.com/2019/09/how-to-write-test-class-basics-salesforce.html
I hope this will help you to learn how to write a test class very easily
Thanks 😊,
AJINKYA DHAS
[SalesforceKid (http://www.salesforcekid.com)]