I am working on an Org with some old code that is beyond my admin / learing Apex ability to fix. This trigger is throwing errors for two many future calls and it no long serves any purpose in our Org. My first thought was to deactivate it and or comment it out in the Sandbox and deploy a change set. The deployment failed because code coverage is only at 72%. I am assuming that if I can fix the code coverage rather than just turn off the trigger and handler then I can deploy? The trigger has 51% code coverage and the handler has 0%. Trigger
trigger ContactTrigger on Contact (before insert, after insert, after update, before update) {
//
//Created Date : 15 Feb' 2016
//Task : T-476163
//Description : Trigger to update the Geolocation fields on Influencer(Contact) object
//
if(Trigger.isInsert && Trigger.isBefore){
if(System.label.Disable_Influencer_Owner_Change == 'false'){
list<contact> contlist = trigger.new;
for(contact cont: contlist){
cont.InfluencerOwner__c = cont.ownerid;
cont.ownerid = System.label.NewOwnerId;
}
}
}
if(Trigger.isUpdate && Trigger.isBefore){
System.debug('####### Before update cont.influencerOwner__c ');
if(System.label.Disable_Influencer_Owner_Change == 'false'){
list<contact> oldcontlist = trigger.old;
list<contact> newcontlist = trigger.new;
System.debug('####### Before update '+oldcontlist.size());
for(contact cont: newcontlist){
contact oldContact = Trigger.oldMap.get(cont.Id);
/*
if (cont.InfluencerOwner__c != null && cont.ownerid != cont.influencerOwner__c) {
cont.InfluencerOwner__c = cont.ownerid;
cont.ownerid = System.label.NewOwnerId;
}*/
if(cont.influencerOwner__c == null){
System.debug('####### cont.influencerOwner__c '+System.label.NewOwnerId);
cont.InfluencerOwner__c = cont.ownerid;
cont.ownerid = System.label.NewOwnerId;
}
}
}
}
if ( Trigger.isInsert && Trigger.isAfter ) {
//ContactTriggerHandler.afterInsert( Trigger.new );
}
else if ( Trigger.isUpdate && Trigger.isAfter ) {
//ContactTriggerHandler.afterUpdate( Trigger.new, Trigger.oldMap );
}
else if ( Trigger.isUpdate && Trigger.isBefore ) {
//ContactTriggerHandler.beforeUpdate( Trigger.new, Trigger.oldMap );
}
if(Trigger.isAfter){
if(checkRecursive.runOnce())
{
System.debug('######## Contact trigger Called ');
System.debug('########System.Label.Disable_Interface_Flow '+System.Label.Disable_Interface_Flow);
if('False' == System.Label.Disable_Interface_Flow){
System.debug('######## Called syncCustomer code');
SendAccountUsingRestApi.syncCustomer();
}
if(Trigger.isUpdate){
if('False' == System.Label.DISABLE_PARDOT_ASSIGNMENT_CALL){
CustomPARDOT.assignProspectsByContact(Trigger.new);
}
}
if('false' == System.Label.DISABLE_RELATIONSHIP_OWNER_SHARING){
InfluencerSharingWithRelationshipOwner.sharewithRelationshipOwner(Trigger.new);
}
System.debug('::CONTACT SENT TO PARDOT::');
}
}
}
Handler
public without sharing class ContactTriggerHandler {
//
//Created Date : 15 Feb' 2016
//Task : T-476163
//Description : Trigger Handler to update the Geolaction fields on Influencer(Contact) object
//
//Method to get all the new inserted records
public static void afterInsert( List<Contact> newContactList ) {
addToGeocodeServiceBatch( newContactList );
}
//Method to get all the updated records where Mailing Address has been changed
public static void afterUpdate( List<Contact> newContactList, Map<Id, Contact> oldContactMap ) {
List<Contact> conToUpdate = new List<Contact>();
for ( Contact con : newContactList ) {
if ( con.MailingStreet != oldContactMap.get(con.Id).MailingStreet
|| con.MailingCity != oldContactMap.get(con.Id).MailingCity
|| con.MailingState != oldContactMap.get(con.Id).MailingState
|| con.MailingPostalCode != oldContactMap.get(con.Id).MailingPostalCode
|| con.MailingCountry != oldContactMap.get(con.Id).MailingCountry ) {
conToUpdate.add( con );
}
}
if( conToUpdate.size() > 0 ) {
addToGeocodeServiceBatch( conToUpdate );
}
}
//Method to nullify Latitude and Longitude on Address change
public static void beforeUpdate( List<Contact> newContactList, Map<Id, Contact> oldContactMap ) {
for ( Contact con : newContactList ) {
if ( con.MailingStreet != oldContactMap.get(con.Id).MailingStreet
|| con.MailingCity != oldContactMap.get(con.Id).MailingCity
|| con.MailingState != oldContactMap.get(con.Id).MailingState
|| con.MailingPostalCode != oldContactMap.get(con.Id).MailingPostalCode
|| con.MailingCountry != oldContactMap.get(con.Id).MailingCountry ) {
con.Location__latitude__s = null;
con.Location__longitude__s = null;
}
}
}
//Method to call the geocode method to update the geolocation fields on Influencer(Contact) object
public static void addToGeocodeServiceBatch( List<Contact> newContactList ){
GeocodeService.geocode(
newContactList
,'Address__c'
,'Location__latitude__s'
,'Location__longitude__s'
,true //true means run @future
);
}
}
Test Class
@isTest
private class TestContactTriggerHandler {
//
//Created Date : 15 Feb' 2016
//Task : T-476163
//Description : Test Case for Contact Trigger Handler
//
//Method to Test the autofill of Location field on Influencer(Contact) record
static testMethod void TestPopulateCategories() {
List<Contact> con = new List<Contact>();
for ( Integer i = 0; i < 2; i++ ) {
con.add( UtilTest.createInfluencer( i, false ) );
}
Test.startTest();
//Testing insert Trigger
insert con;
con = [SELECT Id, Name, MailingStreet, MailingCity, MailingState, MailingCountry, MailingPostalCode FROM Contact];
System.assert( con[0].Name.contains( 'First' ), 'Insert Assert Failed' + con[0].Name );
//Testing Update trigger
con[0].MailingStreet = 'B-16';
update con;
con = [SELECT Id, Name, MailingStreet, Location__latitude__s FROM Contact];
//Testing after Update Trigger
System.assert( con[0].MailingStreet.contains( 'B-16' ), 'Update1 Assert Failed' + con[0].MailingStreet );
//Testing before Update Trigger
System.assertEquals( null, con[0].Location__latitude__s , 'Update2 Assert Failed' );
Test.stopTest();
}
}
ContactTriggerHandlersince you have already commented the references to it. Check and note the test classes for the following classes : SendAccountUsingRestApi, CustomPARDOT and InfluencerSharingWithRelationshipOwner. When validating your change set, select 'Run Specified Tests' and provide the names of the 3 test classes you noted above like : TestClass1,TestClass2,TestClass3 . See if it still fails due to coverage issue. – S.. Jun 28 '18 at 13:57