You need to sign in to do that
Don't have an account?
Guru 91
Code coverage for extended class?
Hi,
Please help me with test class
public with sharing class Tenant_ImprovementAfterUpdateHandler extends TriggerHandlerBase {
Set<Id> selectedUnitIds = new Set<Id>();
Set<Id> opportunityIds = new Set<Id>();
List<Opportunity> opportunityToUpdate = new List<Opportunity>();
public override void qualifyStartingRecords(List<sObject> newList, List<sObject> oldList, Map<ID, sObject> newMap, Map<ID, sObject> oldMap) {
for(String tiId : newMap.keySet()) {
if(newMap.get(tiId).get('Standard_Ti__c') != oldMap.get(tiId).get('Standard_Ti__c')
|| newMap.get(tiId).get('Total_ASTI__c') != oldMap.get(tiId).get('Total_ASTI__c')
|| newMap.get(tiId).get('Shell_Ti__c') != oldMap.get(tiId).get('Shell_Ti__c')
|| newMap.get(tiId).get('Make_Ready_Costs__c') != oldMap.get(tiId).get('Make_Ready_Costs__c')) {
selectedUnitIds.add((Id)newMap.get(tiId).get('Selected_Unit__c'));
}
for(Lease_Analysis_Selected_Unit__c selectedUnit : [SELECT Id, Name, Scenario__c, Scenario__r.Lease_Analysis__c, Scenario__r.Lease_Analysis__r.Opportunity__c FROM Lease_Analysis_Selected_Unit__c WHERE Id =: selectedUnitIds AND Scenario__r.IsPrimary__c = true]) {
opportunityIds.add(selectedUnit.Scenario__r.Lease_Analysis__r.Opportunity__c);
}
}
}
public override void start() {
if(null != opportunityIds && opportunityIds.size() > 0) {
for(Opportunity opp : [SELECT Id, Name, Forecast_Matrix_Date__c FROM Opportunity WHERE Id =: opportunityIds]) {
Opportunity opportunity = new Opportunity(Id = opp.Id);
Boolean needToUpdate = false;
if(opp.Forecast_Matrix_Date__c == null || opp.Forecast_Matrix_Date__c < System.today()) {
needToUpdate = true;
opportunity.Forecast_Matrix_Date__c = System.today();
}
if(needToUpdate) {
opportunityToUpdate.add(opportunity);
}
}
}
}
public override void finish(boolean fromStart){
if(opportunityToUpdate.size() > 0) {
update opportunityToUpdate;
}
}
}
Thanks
Please help me with test class
public with sharing class Tenant_ImprovementAfterUpdateHandler extends TriggerHandlerBase {
Set<Id> selectedUnitIds = new Set<Id>();
Set<Id> opportunityIds = new Set<Id>();
List<Opportunity> opportunityToUpdate = new List<Opportunity>();
public override void qualifyStartingRecords(List<sObject> newList, List<sObject> oldList, Map<ID, sObject> newMap, Map<ID, sObject> oldMap) {
for(String tiId : newMap.keySet()) {
if(newMap.get(tiId).get('Standard_Ti__c') != oldMap.get(tiId).get('Standard_Ti__c')
|| newMap.get(tiId).get('Total_ASTI__c') != oldMap.get(tiId).get('Total_ASTI__c')
|| newMap.get(tiId).get('Shell_Ti__c') != oldMap.get(tiId).get('Shell_Ti__c')
|| newMap.get(tiId).get('Make_Ready_Costs__c') != oldMap.get(tiId).get('Make_Ready_Costs__c')) {
selectedUnitIds.add((Id)newMap.get(tiId).get('Selected_Unit__c'));
}
for(Lease_Analysis_Selected_Unit__c selectedUnit : [SELECT Id, Name, Scenario__c, Scenario__r.Lease_Analysis__c, Scenario__r.Lease_Analysis__r.Opportunity__c FROM Lease_Analysis_Selected_Unit__c WHERE Id =: selectedUnitIds AND Scenario__r.IsPrimary__c = true]) {
opportunityIds.add(selectedUnit.Scenario__r.Lease_Analysis__r.Opportunity__c);
}
}
}
public override void start() {
if(null != opportunityIds && opportunityIds.size() > 0) {
for(Opportunity opp : [SELECT Id, Name, Forecast_Matrix_Date__c FROM Opportunity WHERE Id =: opportunityIds]) {
Opportunity opportunity = new Opportunity(Id = opp.Id);
Boolean needToUpdate = false;
if(opp.Forecast_Matrix_Date__c == null || opp.Forecast_Matrix_Date__c < System.today()) {
needToUpdate = true;
opportunity.Forecast_Matrix_Date__c = System.today();
}
if(needToUpdate) {
opportunityToUpdate.add(opportunity);
}
}
}
}
public override void finish(boolean fromStart){
if(opportunityToUpdate.size() > 0) {
update opportunityToUpdate;
}
}
}
Thanks
Thank you for your response,
Here is my dependent classes
global abstract class TriggerHandlerBase implements ITriggerHandler
{
// -------- Constants --------
// None
// -------- Constructor --------
// None
// -------- Variables --------
// Record if running
private Boolean initiaited = false;
// -------- Properties --------
// None
// -------- Methods --------
// Return if the handler is running
global Boolean isRunning()
{
return initiaited;
}
// Set the running to true, called from the dispatcher
global void startRunning()
{
initiaited = true;
}
// Set the running back to false, called from the dispatcher
global void stopRunning()
{
initiaited = false;
}
// Required overrides
global abstract void qualifyStartingRecords(List<sObject> newList,
List<sObject> oldList, Map<ID, sObject> newMap, Map<ID, sObject> oldMap);
global abstract void start();
// Optional overrides
global virtual void qualifyReEntryRecords(List<sObject> newList,
List<sObject> oldList, Map<ID, sObject> newMap,
Map<ID, sObject> oldMap) {
}
global virtual void reEntry()
{
}
global virtual void finish(BooleanfromStart)
{
}
global interface ITriggerHandler
{
Boolean isRunning();
void startRunning();
void stopRunning();
void qualifyStartingRecords(List<sObject> newList, List<sObject> oldList,
Map<ID, sObject> newMap, Map<ID, sObject> oldMap);
void start();
void qualifyReEntryRecords(List<sObject> newList, List<sObject> oldList,
Map<ID, sObject> newMap, Map<ID, sObject> oldMap);
void reEntry();
void finish(Boolean fromStart);
}