+ Start a Discussion
Bramha1Bramha1 

Need Soql Query if it is possible

Hi,

 

    I have a Object called download__c and a field agg__c. I have lots of records(e.g 100) in download__c which has agg__c(this is not a picklist) will be having  values like Value1, Value2, Valu3 and Value4. So all 100 records will have any value from the four.  I can get the these values by doing a query on download__c and iterate through all the records and store the agg__c values in a Set.  Is there any other way i could the Set of values. is there any other possibility doing anything in the query ?

 

 

Cheers

 

Bramha

Best Answer chosen by Admin (Salesforce Developers) 
Bramha1Bramha1

Hi,

 

  I have got the result what i expected using AggregateResult object.

 

List<AggregateResult> ar = [Select agg__c a , count(Id) from Download__c Group By agg__c ] ;

 

for(AggregateResult  a : ar) {

System.debug('***Hello123***' +a.get('a'));

}

 

 

Thanks

 

Bramha

 

 

All Answers

Jake GmerekJake Gmerek

So you want to create a set of all the distinct values stored in agg__c, correct?

Bramha1Bramha1

Yes, is it possible with a query. I am looking around the AggregatorResults if i could get any solution. If you get a better solution please let me know.

 

 

Cheers

 

Bramha

Bramha1Bramha1

Hi,

 

  I have got the result what i expected using AggregateResult object.

 

List<AggregateResult> ar = [Select agg__c a , count(Id) from Download__c Group By agg__c ] ;

 

for(AggregateResult  a : ar) {

System.debug('***Hello123***' +a.get('a'));

}

 

 

Thanks

 

Bramha

 

 

This was selected as the best answer