You need to sign in to do that
Don't have an account?
Very urgent - migration to prod ( Test class coverage 60%)
We have a migration and below is the class causing issue because of code coverage . I have attached the test class to.
Help really appreciated as its very urgent
global class Migrate_Account_Class_Batch implements Schedulable
{
global void execute(SchedulableContext sc)
{
// query to get the lastupdate date from the Custom Settings - MigrationDate
MigrationDate__c MigDt =[SELECT Id,LastUpdateDate__c FROM MigrationDate__c where Name like 'Account%' order by LastUpdateDate__c desc Limit 1];
if(MigDt <> null)
{
DateTime Dt = MigDt.LastUpdateDate__c;
List<Account> accounts = [Select Id ,EMC_Match__c, DUNS_Match__c from Account where LastModifiedDate > :Dt AND (EMC_Match__c = true OR DUNS_Match__c = true)];
//inset a new entry in the Custom Setting - MigrationDate
MigrationDate__c mg = new MigrationDate__c(Name='Account'+ System.now(),LastUpdateDate__c=System.Today());
insert mg;
// Define connection id
Id networkId = ConnectionHelper.getConnectionId('Hartford Life GBD');
// System.debug('After networkId');
Set<Id> localAccountSet = new Set<Id>();
List<Account> localAccounts = new List<Account>();
// only share records created in this org, do not add accounts received from another org.
for (Account newAccounts : accounts )
{
System.Debug('EMC: ' + newAccounts.EMC_Match__c + ', Duns:' + newAccounts.DUNS_Match__c );
if (newAccounts.Id != null && (newAccounts.EMC_Match__c == true || newAccounts.DUNS_Match__c == true ))
{
localAccountSet.add(newAccounts.Id);
// System.Debug('Size: '+localAccountSet.size()+', Id:' + newAccounts.Id);
localAccounts.add(newAccounts);
}
}
if (localAccountSet.size() > 0)
{
// System.debug('Before Partner Network');
List<PartnerNetworkRecordConnection> accountConnections = new List<PartnerNetworkRecordConnection>();
for (Account newAccount : localAccounts) {
if (localAccountSet.contains(newAccount.Id))
{
PartnerNetworkRecordConnection newConnection =
new PartnerNetworkRecordConnection(
ConnectionId = networkId,
LocalRecordId = newAccount.Id,
SendClosedTasks = false,
SendOpenTasks = false,
SendEmails = false,
RelatedRecords = 'Location_Assignment__c');
accountConnections.add(newConnection);
// System.Debug('Network Id: '+networkId+', Account Id:' + newAccount.Id+', Related:' + newConnection.RelatedRecords);
}
}
if (accountConnections.size() > 0 )
{
database.insert(accountConnections);
System.debug('After Database commit');
// Migrate_LocAssign_Class_Batch LocAssign = new Migrate_LocAssign_Class_Batch();
// LocAssign.setPCLocAssign();
}
}
}
}
}
Test Class
Test class
@isTest private class Test_Migrate_Account_Class_Batch {
static testMethod void myUnitTest() { Test.startTest(); String sch = '0 0 * * * ?'; system.debug('started '+sch); Id a = system.schedule('Acc Job Test', sch, new Migrate_Account_Class_Batch()); CronTrigger ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :a]; System.assertEquals(sch,ct.CronExpression); // Verify the job has not run System.assertEquals(0, ct.TimesTriggered); // Verify the next time the job will run System.assertEquals('2012-02-11 00:00:00', String.valueOf(ct.NextFireTime)); Test.stopTest(); }