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
Vinu VargheseVinu Varghese 

Adding to Rollup Summary value

How to get the next SlNo after the following query. Suppose the following query returns value 0 and I wanted to added 1 to the SlNo to find the next SlNo. How can I achieve this. What is the best way to do this. Please note that Serial_Number_Counter__c is defined as a Rollup summary.

List<AggregateResult> SlNo = [Select Name, max(Serial_Number_Counter__c) from Deposit__c group by name];

Thanks
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vinu,

In case if you want to add 1 to all the records then you will have to iterate over the list of aggregate result a simple example of iterating over list of aggregate results is below you can modify it as per your scenario:
 
AggregateResult[] groupedResults
  = [SELECT CampaignId, AVG(Amount)
      FROM Opportunity
      GROUP BY CampaignId];
for (AggregateResult ar : groupedResults)  {
    System.debug('Campaign ID' + ar.get('CampaignId'));
    System.debug('Average amount' + ar.get('expr0'));
}
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.