I have a SOQl query calculating the distance between two sets of coordinates. In the select statement the alias name for this calculated distance is ‘dist’ I have a pageblocktable in my visual force page and would like to display the alias ‘dist’ as a column value. I tried the below
SOQL query:
projects = [Select Id, Name, DISTANCE( Decimal_LatLon__c,GEOLOCATION( :latt, :lonn) , 'mi') dist, Client_Account__r.Name, Site_Name__c, Site_Address__c, Site_City__c, CreatedDate, Coordinate_Type__c, Ordering_Company__r.Name from pse__Proj__c where DISTANCE( Decimal_LatLon__c,GEOLOCATION( :latt, :lonn) , 'mi') < 1.0
order by DISTANCE( Decimal_LatLon__c,GEOLOCATION( :latt, :lonn) , 'mi')]
Used the below syntax to display in visual force page. The page complies
<apex:column value="${!pcon['dist']}" headerValue="Distance" />
But I get the following error. Based on the error, it seems that it is complaining because ‘dist’ is not a field in the Sobject pse__Proj__c. Is there a way to display the value of an alias column in Visual force page?
Invalid field dist for SObject pse__Proj__c Error is in expression '${!pcon['dist']}' in component in page sitesearchpage Error evaluating dynamic reference 'dist'
VF pageblocktable
<apex:pageBlockTable var="pcon" value="{!projs}" >
<apex:column headerValue="Project Number">
<apex:outputLink value="{!sandURL}{!pcon.Id}" target="_blank">{!pcon.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Ordering Company">
<apex:outputField value="{!pcon.Ordering_Company__r.Name}"/>
</apex:column>
<apex:column headerValue="Site Name">
<apex:outputField value="{!pcon.Site_Name__c}"/>
</apex:column>
<apex:column headerValue="Site Address">
<apex:outputField value="{!pcon.Site_Address__c}"/>
</apex:column>
<apex:column headerValue="Site City">
<apex:outputField value="{!pcon.Site_City__c}"/>
</apex:column>
<apex:column headerValue="Client Company">
<apex:outputField value="{!pcon.Client_Account__r.Name}"/>
</apex:column>
<apex:column headerValue="Created Date">
<apex:outputField value="{!pcon.CreatedDate}"/>
</apex:column>
<apex:column headerValue="Coordinate Type">
<apex:outputLabel value="{!IF(pcon.Coordinate_Type__c == 2, 'Full Address', IF(pcon.Coordinate_Type__c == 3, 'City State', IF(pcon.Coordinate_Type__c == 5, 'Zip', IF(pcon.Coordinate_Type__c == 1, 'User Specified', ' '))))}" />
</apex:column>
<apex:column value="${!pcon['dist']}" headerValue="Distance" />
<!--<apex:outputField value="${!pcon['dist']}"/> -->
<!--</apex:column> -->
</apex:pageBlockTable>
In the controller, the property 'projs' is defined as below
public List<pse__Proj__c> projs{
get{
if (setConProj != null) {
return (List<pse__Proj__c>)setConProj.getRecords();
}
else {
return null;
}
}
set;
}
outputText
? That is,<apex:column><apex:outputText value="{!pcon['dist']}" /></apex:column>
?