2

Query Results

@RemoteAction
global static List<pba_listingobj__c> getAccountstages(String namejs) 
{   
 return [SELECT sales_stage__c FROM pba_listingobj__c where Account_lookup__r.Name=:namejs GROUP BY sales_stage__c];        
}

Where Account_lookup__c is Lookup to Account.

Field name: Account_lookup__c

How to have unique Stages (sales_stage__c)(values can be : Closed Won, Prospect)?

Records:

  1. Prospect

  2. Closed Won

  3. Closed Won

  4. Closed Won

Desired Output: As shown in the above screenshot.

  1. Prospect

  2. Closed Won

1

When you use a GROUP BY clause, the query returns List<AggregateResult>.

@RemoteAction
global static List<AggregateResult> getAccountStages(String name)
{
    // same query
}

You may wish to simply return a List<String>, depending on how you consume this data downstream.

@RemoteAction
global static List<String> getAccountStages(String name)
{
    List<String> stages = new List<String>();
    for (AggregateResult aggregate : [/*query*/])
        stages.add((String)aggregate.get('Sales_Stage__c'));
    return stages;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.