You need to sign in to do that
Don't have an account?
Guru 91
Code coverage for trigger?
Hi
needed help in Code coverage
trigger UnitTrigger on Unit__c (before insert, before update) {
if(trigger.isBefore){
Map<String, Id> unitRecTypeMap = new Map<String, Id>();
for(RecordType r: [Select Id, Name From RecordType Where sObjectType = 'Unit__c'])
unitRecTypeMap.put(r.Name,r.Id);
if(trigger.isInsert){
for(Unit__c u: trigger.new){
// flipping Unit to Retired if its inserted with 0 area
if(u.Area_SF__c == 0)
{u.Available__c = false; u.RecordTypeId = unitRecTypeMap.get('Retired'); }
// initializing unit as unavailable if its Raw Land or Sold
else if(u.Lifecycle__c == 'Sold')
u.Available__c = false;
// initializing the unit availability to true when its first inserted with non-zero (includes null) area
else
u.Available__c = true;
}
}
set<Id> unitIdSet = new set<Id>();
if(trigger.isUpdate){
for(Unit__c u: trigger.new){
// updating sold units as unavailable
if (u.Lifecycle__c == 'Sold')
{u.Available__c = false; u.IsAvailabilityUpdatedByUser__c = false;}
// Active --> Retired
if(u.Area_SF__c == 0)
{u.Available__c = false; u.IsAvailabilityUpdatedByUser__c = false; u.RecordTypeId = unitRecTypeMap.get('Retired'); }
// Retired --> Active (very unlikely that this code will be executed)
if(u.Area_SF__c != 0 && trigger.oldMap.get(u.Id).Area_SF__c == 0){
u.RecordTypeId = unitRecTypeMap.get('Active');
if(u.Lifecycle__c != 'Sold')
unitIdSet.add(u.Id);
}
}
//Informatica, SSIS and other Sys Admins will skip this
Id SysAdminId = Label.System_Administrator;
if(LeaseUnitRelationManagement.exitUnitTrigger == false && UserInfo.getProfileId() != SysAdminId){
for(Unit__c u: trigger.new){
if(u.Available__c != trigger.oldMap.get(u.Id).Available__c && u.IsAvailabilityUpdatedByUser__c == false){
u.IsAvailabilityUpdatedByUser__c = true;
}
}
}
}
// unitIdSet - units that need to be re-evaluated for Availability (very unlikely that this code will be executed)
if(unitIdSet.size()>0 && unitIdSet != null){
UnitTriggerManagement.reEvaluateUnitsforAvailability(unitIdSet);
}
} // end of isBefore
}
needed help in Code coverage
trigger UnitTrigger on Unit__c (before insert, before update) {
if(trigger.isBefore){
Map<String, Id> unitRecTypeMap = new Map<String, Id>();
for(RecordType r: [Select Id, Name From RecordType Where sObjectType = 'Unit__c'])
unitRecTypeMap.put(r.Name,r.Id);
if(trigger.isInsert){
for(Unit__c u: trigger.new){
// flipping Unit to Retired if its inserted with 0 area
if(u.Area_SF__c == 0)
{u.Available__c = false; u.RecordTypeId = unitRecTypeMap.get('Retired'); }
// initializing unit as unavailable if its Raw Land or Sold
else if(u.Lifecycle__c == 'Sold')
u.Available__c = false;
// initializing the unit availability to true when its first inserted with non-zero (includes null) area
else
u.Available__c = true;
}
}
set<Id> unitIdSet = new set<Id>();
if(trigger.isUpdate){
for(Unit__c u: trigger.new){
// updating sold units as unavailable
if (u.Lifecycle__c == 'Sold')
{u.Available__c = false; u.IsAvailabilityUpdatedByUser__c = false;}
// Active --> Retired
if(u.Area_SF__c == 0)
{u.Available__c = false; u.IsAvailabilityUpdatedByUser__c = false; u.RecordTypeId = unitRecTypeMap.get('Retired'); }
// Retired --> Active (very unlikely that this code will be executed)
if(u.Area_SF__c != 0 && trigger.oldMap.get(u.Id).Area_SF__c == 0){
u.RecordTypeId = unitRecTypeMap.get('Active');
if(u.Lifecycle__c != 'Sold')
unitIdSet.add(u.Id);
}
}
//Informatica, SSIS and other Sys Admins will skip this
Id SysAdminId = Label.System_Administrator;
if(LeaseUnitRelationManagement.exitUnitTrigger == false && UserInfo.getProfileId() != SysAdminId){
for(Unit__c u: trigger.new){
if(u.Available__c != trigger.oldMap.get(u.Id).Available__c && u.IsAvailabilityUpdatedByUser__c == false){
u.IsAvailabilityUpdatedByUser__c = true;
}
}
}
}
// unitIdSet - units that need to be re-evaluated for Availability (very unlikely that this code will be executed)
if(unitIdSet.size()>0 && unitIdSet != null){
UnitTriggerManagement.reEvaluateUnitsforAvailability(unitIdSet);
}
} // end of isBefore
}
Best Answer chosen by Guru 91
Raj Vakati
try this code