+ Start a Discussion

Facing error in future method :"Line: 3, Column: 24 static can only be used on methods of a top level type"

Please let me know hoe to resolve this error as I am new in SFDC developement

Create a field on the Account object called 'Number_of_Contacts__c' of type Number. This field will hold the total number of Contacts for the Account.
Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.
For each Account ID passed to the method, count the number of Contact records associated to it and update the 'Number_of_Contacts__c' field with this value.
public class AccountProcessor {
    public static void countContacts(List<ID> accid1)
      List<Account> acc = [select Id,name from account where Id In: accid1];
       List<Account> updateacc = new List<Account>();
        for (Account a1 : acc)
            a1.Number_of_Contacts__c = [select count() from contact where accountId IN: a1.Id];
        update updateacc;


Thanks :)