You need to sign in to do that
Don't have an account?
sumit d
test class for opportuntyTriggerHelper
Hi All,
my opportunityTriggerHelper is given below:-
public without sharing class OpportunityTriggerHelper {
public static List<Opportunity> newOpportunity = new List<Opportunity>();
public static List<Opportunity> oldOpportunity = new List<Opportunity>();
public static Map<Id, Opportunity> newMapOpportunity = new Map<Id, Opportunity>();
public static Map<Id, Opportunity> oldMapOpportunity = new Map<Id, Opportunity>();
public static boolean runTrigger = TRUE;
public static void populateArrDifference(){
list<Opportunity> releventOpportunities = new list<Opportunity>();
for( Opportunity opp : newOpportunity ){
if( opp.Type == 'Renewal Expansion' &&
( trigger.isInsert || ( opp.Type != oldMapOpportunity.get( opp.Id ).Type ))){
releventOpportunities.add( opp );
}
}
try{
set<String> oppAcceptedTypes = new set<String>
{ 'New Business', 'Renewal',
'Winback', 'AE Winback (>120 days post exp)'
};
set<Id> accountIds = new set<Id>();
if( releventOpportunities.size() > 0 ){
for( Opportunity opp : releventOpportunities ){
accountIds.add( opp.AccountId );
}
}
List<Opportunity> opportunities = [ SELECT Id, AccountId, Name,
Description, StageName,
ARR_Estimation__c
FROM Opportunity
WHERE AccountId IN: accountIds
AND StageName = 'Closed Won'
AND Type IN :oppAcceptedTypes
ORDER BY CreatedDate DESC
];
map<Id, Opportunity> mapAccountIdToArrEstimation = new map<Id, Opportunity>();
if( opportunities.size() > 0 ){
for( Opportunity opp : opportunities ){
if( ! mapAccountIdToArrEstimation.containsKey( opp.AccountId ) ){
mapAccountIdToArrEstimation.put( opp.AccountId, opp );
}
}
}
list<Opportunity> opportunityToUpdate = new list<Opportunity>();
for( Opportunity opp : releventOpportunities ){
if( mapAccountIdToArrEstimation.containsKey( opp.AccountId ) ){
opp.Recent_Closed_Won_Opportunity__c = mapAccountIdToArrEstimation.get( opp.AccountId ).Id;
}
}
}
catch( Exception e ){
releventOpportunities.get(0).addError( e.getMessage() );
}
}
}
how to write test class for it?
Any suggestions?
my opportunityTriggerHelper is given below:-
public without sharing class OpportunityTriggerHelper {
public static List<Opportunity> newOpportunity = new List<Opportunity>();
public static List<Opportunity> oldOpportunity = new List<Opportunity>();
public static Map<Id, Opportunity> newMapOpportunity = new Map<Id, Opportunity>();
public static Map<Id, Opportunity> oldMapOpportunity = new Map<Id, Opportunity>();
public static boolean runTrigger = TRUE;
public static void populateArrDifference(){
list<Opportunity> releventOpportunities = new list<Opportunity>();
for( Opportunity opp : newOpportunity ){
if( opp.Type == 'Renewal Expansion' &&
( trigger.isInsert || ( opp.Type != oldMapOpportunity.get( opp.Id ).Type ))){
releventOpportunities.add( opp );
}
}
try{
set<String> oppAcceptedTypes = new set<String>
{ 'New Business', 'Renewal',
'Winback', 'AE Winback (>120 days post exp)'
};
set<Id> accountIds = new set<Id>();
if( releventOpportunities.size() > 0 ){
for( Opportunity opp : releventOpportunities ){
accountIds.add( opp.AccountId );
}
}
List<Opportunity> opportunities = [ SELECT Id, AccountId, Name,
Description, StageName,
ARR_Estimation__c
FROM Opportunity
WHERE AccountId IN: accountIds
AND StageName = 'Closed Won'
AND Type IN :oppAcceptedTypes
ORDER BY CreatedDate DESC
];
map<Id, Opportunity> mapAccountIdToArrEstimation = new map<Id, Opportunity>();
if( opportunities.size() > 0 ){
for( Opportunity opp : opportunities ){
if( ! mapAccountIdToArrEstimation.containsKey( opp.AccountId ) ){
mapAccountIdToArrEstimation.put( opp.AccountId, opp );
}
}
}
list<Opportunity> opportunityToUpdate = new list<Opportunity>();
for( Opportunity opp : releventOpportunities ){
if( mapAccountIdToArrEstimation.containsKey( opp.AccountId ) ){
opp.Recent_Closed_Won_Opportunity__c = mapAccountIdToArrEstimation.get( opp.AccountId ).Id;
}
}
}
catch( Exception e ){
releventOpportunities.get(0).addError( e.getMessage() );
}
}
}
how to write test class for it?
Any suggestions?
for example for the followign if
if( opp.Type == 'Renewal Expansion' &&
( trigger.isInsert || ( opp.Type != oldMapOpportunity.get( opp.Id ).Type )))
you should insert an opportunity with the type "Renewal Expansion" or update an opportunity and change the Type.