Tuesday 26 November 2013

Using Aggregate Function and Querying records using AggregateResult method in Salesforce

Processing your aggregate function in your apex class or trigger.

Whenever if you are using aggregate function in your SOQL query you must group those selected fields in your query. In the below query i have queried profileId field so need to group this field.

To process your aggregate function soql query you must use the AggregateResult 

  1. List<AggregateResult> ui=[Select count(Id) cnt,ProfileId from User where Profile.Name='Customer Portal Manager Custom' group by ProfileId];
  2. for(AggregateResult ar: ui)
  3. {
  4.     String str = '' + ar.get('ProfileId') ;  //Get profileId
  5.     String str1 = '' + ar.get('cnt') ;  //Get count of Id using the alias name
  6. }

1 comment:

  1. Nice article Kept Up
    214 Read About Area Code which State Locations, cities, Timezone.

    ReplyDelete

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...