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
inanskarinanskar 

Plz Check the code

Hii All,

I have Scenario

that i made custom fireld

DATA Type:picklist

Field:Days__c

values{MOn,Tue,Wed,Thu,Fri,Sat,Sun]

and i have to get the o/p as Name :Mike NUmber of  working daysDays :4

 

 

public with sharing class Workdays

{

  public Workdays() {  }

 Account a = new Account();

 List<Account> a1; 

public list<Account> getAcclist()

 {  return a1; }

 public PageReference Attendance()

 {

 a1=[select count(id),name,Days__c from Account where name=:a.name Group by Days__c];

 public Account getAccount() {  return a; }

 

}

and i'm getting ERror:ErrorError: Compile Error: Field must be grouped or aggregated: Name at line 14 column 6

 

can u plz guide how to apply group by function for this code

Thanks in Advance

 

Baktash H.Baktash H.

public PageReference Attendance()

 

when you write PageReference you need to return a PageReference...

meerameera

Hi,

 

As specified in the error if it an aggregate query that you are using then all the fields that you specified in select statement should be either used in group statement or it should be aggregated. Here name is not included in any of this. May be you can use

a1=[select count(id),name,Days__c from Account where name=:a.name Group by Days__c,name];

inanskarinanskar

Hii meera

Yeah i'll look on that way

and tried to  write the code in another way

can u have a look at this code 

 

public  class GroupedQuery{  

 public string GroupBy1 {get;set;}   

 public integer Count {get;set;}   

public List<GroupedQuery> queryResults {get;set;} 

   public GroupedQuery() 

   {     

        List<Account> queries = [select id, Name,Count(Days__c) CountResult from Account group by Name];     } 

queryResults = new List<GroupedQuery>();

 

for(Account query: queries)

{    GroupedQuery myObject = new GroupedQuery();   

myObject.Count = Integer.valueOf(query.get(CountResult)); 

  myObject.GroupBy1 = String.valueOf(query.get('Name')); 

  queryResults.Add(myObject);

}

}   

 

and i'm getting the error

Compile Error: unexpected token: '=' at line 11 column 13     

Canu u guys plz get me the error free code.. i tried with my little knwoledge in salesforce.. hope this code may extend my capabilities to learn on salesforce

Thanks in Advance

                        

Starz26Starz26

this will solve that specific error

 

public  class GroupedQuery{  

 public string GroupBy1 {get;set;}   

 public integer Count {get;set;}   

public List<GroupedQuery> queryResults {get;set;} 

   public GroupedQuery() 

   {     

        List<Account> queries = [select id, Name,Count(Days__c) CountResult from Account group by Name];

queryResults = new List<GroupedQuery>();

 

for(Account query: queries){

   GroupedQuery myObject = new GroupedQuery();   

myObject.Count = Integer.valueOf(query.get(CountResult)); 

  myObject.GroupBy1 = String.valueOf(query.get('Name')); 

  queryResults.Add(myObject);

}
}
}   

 

inanskarinanskar

Thanks for ur help Starz26.

But it's giving a Compile Error: Variable does not exist: CountResult at line 23 column 46

hchhch

CountResult  is the "count(Days__c)" value. It is not a variable. It should be given in quotes.

Starz26Starz26

Well, I said it would only solve that ONE specific error :)

 

As the above poster stated, change

 

myObject.Count = Integer.valueOf(query.get(CountResult));



to

 

myObject.Count = Integer.valueOf(query.get('CountResult'));