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
Palash Rana 8Palash Rana 8 

How to Display List of Aggregated result via workbench

I want to display List of Aggregated result i.e Id,Name, Count,but cant get it as i get Null Id iall the retrived records
@RestResource(urlMapping='/GetDuplicateReord/*')
global class duplicateRecords {
    
    @HttpGet
    global static List<AccountInfo> getRecords(){
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        List<AggregateResult> account=[SELECT Name,Prospect_Code__c , Count(id) ids  FROM Account where Id Not In (Select AccountId from Contact)
                         And Id Not In (Select AccountId from Opportunity) GROUP BY Name, Prospect_Code__c  HAVING count(Id)>1];

        List<AccountInfo> r_accounts = new List<AccountInfo>();                

        for(AggregateResult acc:account){
        AccountInfo racc_info = new AccountInfo();
		racc_info.Id=acc.Id;
        //racc_info.Name=acc.Name;
        //racc_info.prospectCode=acc.prospectCode;  
            
        r_accounts.add(racc_info);    
        }
        return r_accounts;
    }
    
    global class AccountInfo{
        String Id;
	    String Name;
      //  String prospectCode;
      
    }
}

Workbench records that i get using GET method
Palash Rana 8Palash Rana 8
I did some R&D with my code and get the reults.
And not it is getting me the result i needed
Below is the code
@RestResource(urlMapping='/GetDuplicateReord/*')
global class duplicateRecords {
    
    @HttpGet
    global static List<AccountInfo> getRecords(){
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        List<AggregateResult> account=[SELECT Name,Prospect_Code__c , Count(id) ids  FROM Account where Id Not In (Select AccountId from Contact)
                         And Id Not In (Select AccountId from Opportunity) GROUP BY Name, Prospect_Code__c  HAVING count(Id)>1];

        List<AccountInfo> r_accounts = new List<AccountInfo>();                

        for(AggregateResult acc:account){           
        r_accounts.add(new AccountInfo(acc));    
        }
        return r_accounts;
    }
    
    global class AccountInfo{
        String Id{get;set;}
        String Name{get;set;}
        String ProspectCode{get;set;}
      
        AccountInfo(AggregateResult acc)
        {
           Id=String.valueOf(acc.get('ids'));
           Name=(String) acc.get('Name');
           ProspectCode=(String) acc.get('Prospect_Code__c');
        }
    }
}