Activity Forums Salesforce Discussions How can write the Aggregate query and display the result of Aggregate query in Salesforce ?

  • How can write the Aggregate query and display the result of Aggregate query in Salesforce ?

  • Arun

    Member
    January 16, 2020 at 1:45 pm

    How can write the Aggregate query to get the sum of a field (Assume field datatype is Number or Currency)  and How can display the result of Aggregate Query in Salesforce apex ?

    • This discussion was modified 8 months, 1 week ago by  Arun.
  • Deepanshu Singh

    Member
    January 18, 2020 at 5:24 pm

    For the Aggregate Query you have AggregateResult class in apex

    Example

    for(AggregateResult ar : [select count(Id), AccountId
                              from Contact 
                              where AccountId in :accset
                              group by AccountId
                              having count(Id)>2 ])
    {
        contList.add(new Contact(Id = (ID)ar.get('AccountId')));
    }
    try{
        update contList;
    }catch(DMLException exc){
        system.debug("Exception => " + exc.getMessage());
    }

     

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos