function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aryan JhaAryan Jha 

Variable does not exist: accountIdsVariable does not exist: AccountProcessor

public class AccountProcessor {
    @future
    public static void countContacts(List<ID>accountIds)
    {
        List<Account>accounts=[SELECT Id,(SELECT Id FROM Contacts) FROM Account WHERE Id IN:accountIds];
        for(Account acc:accounts)
        {
            acc.Number_Of_Contacts__c=acc.Contacts.size();
}
        update accounts;
    }


}

@istest
public class AccountProcessorTest {
@istest
    static void CountContactTest()
    {
        List<Account>accounts=new List<Account>();
        for(Integer i=0;i<300;i++)
        {
            accounts.add(new Account(Name='test account'+i));
        }
        insert accounts;
        List<Contact>contacts=new List<Contact>();
        List<Id>accountId=new List<Id>();
        for(Account a:accounts)
        {
            contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
            accountId.add(a.id);    
        }
        insert contacts;
        Test.startTest();
        AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
        for(Account acc:accs)
        {
            system.assertEquals(1,acc.Number_Of_Contacts__c);
        }
    }
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Aryan,

Can you try giving a space after : in the soql i.e. try changing soql line to below way?

List<Account>accounts=[SELECT Id,(SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds];

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Aryan JhaAryan Jha
Sir can u please test it for me becoz i am new in apex language it will be helpfull
ravi soniravi soni
hi Aryan Jha,
the error is coming from this line : AccountProcessor.countContacts(accountIds);
In your test class replace above line with this line : AccountProcessor.countContacts(accountId); 
I am sure your requirment will be fulfill.
let me know if it helps you and marking it as best answer.
Thank  you