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
Sarah SSarah S 

How do I call this class from Execute Anonymous Window ?

Hello,
Please help me, how do I call below class from the anonymous window. I am not finding a way to pass IDs as parameter.
I want pass record Ids of Account for example this 0010I00001hMhFIQA0. 
___________________________ 
public class AccountClass {
    public static void CountMyContacts(Set<ID> recordIds){
    List<Account> accs = [Select Id, Name from Account Where Id IN :recordIds];
    for (Account a : accs){
    List<Contact> Cons = [Select Id, Name from Contact Where AccountId = :a.Id];
        integer ConCount = Cons.size();
        system.debug( Account.Name + 'account has' + ConCount + 'number of contacts');
       }
    }            
}
Best Answer chosen by Sarah S
lakslaks
Hi Sarah,

This should work.

Set<ID> idSet = new Set<ID>{'0016F00003AWlgkQAD','0016F00002pCFNPQA4'};
AccountClass.CountMyContacts(idSet);

Regards,
Lakshmi.

All Answers

Raj VakatiRaj Vakati
Like this below 
 
Map<Id,Account> accs = new Map<Id,Account>([Select id , Name from Account]) ; 
AccountClass.CountMyContacts(accs.keySet());

 
lakslaks
Hi Sarah,

This should work.

Set<ID> idSet = new Set<ID>{'0016F00003AWlgkQAD','0016F00002pCFNPQA4'};
AccountClass.CountMyContacts(idSet);

Regards,
Lakshmi.
This was selected as the best answer
lakslaks
Please mark it as the Best Answer if it solved your problem.
Sarah SSarah S
Thanks Laxmi, it worked.