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
Ramana123Ramana123 

I have a custom object named task ,which have lookup with Account.I am trying to print task related records using wrapper class.But i am getting error like -----only aggregate expressions use field aliasing

public class taskSelectClassController {
 
     
    public List<wraptask> wraptaskList {get; set;}
    public List<task> selectedtasks{get;set;}
     
    public taskSelectClassController(){
        if(wraptaskList == null) {
            wraptaskList = new List<wraptask>();
            for(task a: [select AccountId,task Name from task limit 10]) {
               
                wraptaskList.add(new wraptask(a));
            }
        }
    }
 
    public void processSelected() {
    selectedtasks = new List<task>();
 
        for(wraptask wraptaskObj : wraptaskList) {
            if(wraptaskObj.selected == true) {
                selectedtasks.add(wraptaskObj.acc);
            }
        }
    }
 
 
    
    public class wraptask {
        public task acc {get; set;}
        public Boolean selected {get; set;}
 
      
        public wraptask(task a) {
            acc = a;
            selected = false;
        }
    }
}
Ravindra Kashyap 7Ravindra Kashyap 7
Hi Srikanth,

for(task a: [select AccountId,task Name from task limit 10])

In the above line, when you are writing SOQL like "task Name" then here while executing your query SF thinks like you are creating Alias for "task" as "Name". But in SOQL Aliasing is only supported by Aggregate method/values.

Just try to give the correct field name without space then it will work. Please try the below code and let me know if it helps you to resolve this problem or not.
 
public class taskSelectClassController {
     
    public List<wraptask> wraptaskList {get; set;}
    public List<task> selectedtasks{get;set;}
     
    public taskSelectClassController(){
        if(wraptaskList == null) {
            wraptaskList = new List<wraptask>();
            //-- if task is custom object then, you need to change this query
            //for(task a: [select AccountId,task Name from task limit 10]) 
           for(Task__c  a: [select AccountId,Name from Task__c limit 10])  {               
                wraptaskList.add(new wraptask(a));
            }
        }
    }
 
    public void processSelected() {
    selectedtasks = new List<task>();
        for(wraptask wraptaskObj : wraptaskList) {
            if(wraptaskObj.selected == true) {
                selectedtasks.add(wraptaskObj.acc);
            }
        }
    }
 
    public class wraptask {
        public task acc {get; set;}
        public Boolean selected {get; set;}      
        public wraptask(task a) {
            acc = a;
            selected = false;
        }
    }
}

 
Ramana123Ramana123
hii sir, > tnx for the code. i have another requirement i have a detail page button on the the account, when i click it then visualforce page will open . when enabled the checkbox then those records should be assigned to that account as child records. ( i have lookup relation in custom object with account ) can you help me on this