Find your content:

Search form

You are here

Can anybody explain what is wrong in below code?

 
Share

I want to get field label from a fieldSet. I have given below my component code where i want to display fieldSet Labels only.

<apex:component controller="LeftBarComponentController">   
    <apex:pageBlock >
      <apex:pageblocksection title="Personal Information">  
                <apex:repeat value="{!fields}" var="f">                 
                    <apex:outputText value="{!con[f.label]}">                    
                    </apex:outputText>                    
                </apex:repeat>  
            </apex:pageblocksection>
   </apex:pageBlock>
</apex:component> 

My controller code is as follows -

public Application__c con{get;set;}
//User cid = [Select id,ContactId from User where id =:UserInfo.getUserId()];
String  ids ='003J00000057btk';
Id tempId = ids;
Contact AppId = [select AppId__c from Contact where id=:tempId ];


public LeftBarComponentController(){
    this.con = getApplicationDetails();
}

 public List<schema.fieldsetmember> getFields() {  
    return SObjectType.Application__c.FieldSets.ApplicationStatusFieldset.getFields();  
}  

public Application__c getApplicationDetails() { 
    String query = 'SELECT ';  
    for(Schema.FieldSetMember f : this.getFields()) {  
        query += f.getFieldPath() + ', ' ;  
        query += f.getLabel() + ', ' ; 
    }  
    query = query+'Id FROM Application__c where id =\''+AppId.AppId__c +'\'' ;
    return Database.query(query);  
} 

When i try to run the component i am getting following error -

only aggregate expressions use field aliasing

An unexpected error has occurred. Your development organization has been notified.

Debug shows following query - 03:19:53.060

(60864000)|USER_DEBUG|[25]|DEBUG|#########SELECT Application Started, Application Submitted, Application Complete, Id FROM Application__c where id ='a0BJ0000002kIbLMAU'

Thanks in advance


Attribution to: Pramod Kumar

Possible Suggestion/Solution #1

It looks like you are querying the field labels (e.g Application Started) rather than the API names (which I would expect to be Application_Started__c).

The SOQL parser interprets 'Application Started' as an attempt to query back the field 'Application' and alias it to 'Started', hence the error about field aliasing.

You don't need to append the label to the query as well as the result of getFieldPath().


Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5038

My Block Status

My Block Content