Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/287646104638586881
added 234 characters in body
Source Link
Pramod Kumar
  • 5.3k
  • 15
  • 60
  • 86

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

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.

Thanks in advance

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

Source Link
Pramod Kumar
  • 5.3k
  • 15
  • 60
  • 86

Can anybody explain what is wrong in below code?

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.

Thanks in advance