• Dave Spragg
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Admittedly I have lame tests but I can't get the coverage to include the code in my loop and have tried several ways. The auto indentation is messed up in my test class.. might be a hint but I don't get it.  When I check the challenge it returns:
Challenge Not yet complete... here's what's wrong: 
The 'AccountProcessor' class did not achieve 100% code coverage via your test methods. Make sure that you chose 'Run All' tests in the Developer Console at least once before attempting to verify this challenge.

global class AccountProcessor {

    @future
    global static void countContacts(List<Id> recordIds)
    {
        //List<Account> accounts = [Select Id, Name from Account Where Id IN :recordIds];
        for(Account theAccount : [Select Id, Name from Account Where Id IN :recordIds])
        {
            Integer contactCount =0;
            contactCount= [Select COUNT() FROM Contact WHERE Contact.AccountId = :theAccount.Id];
            System.debug('Account/Count:'+ theAccount.Name +' '+contactCount);
            
            theAccount.Number_of_Contacts__c= contactCount;
            update theAccount;
        }
    }
}

@IsTest
private class AccountProcessorTest
{
    @IsTest
    private static void testAccountProcessor()
    {
        List<Id> listOfIds= new List<Id>{'0011500001DH89EAAT','0011500001DH89GAAT','0011500001DH89FAAT'};
        Test.startTest();
            try
            {
                AccountProcessor.countContacts(listOfIds);
            }
        catch(Exception e)
        {
        }
        Test.stopTest();
    }
}