You need to sign in to do that
Don't have an account?
John Upton 8
System.QueryException : Unexpected token '('
I'm trying to use Visualforce charts to show information about from the Contact record associated with the user's User record for the purpose of displaying on our Community.
System.QueryException: unexpected token: '('
Class.Graph2.getPieData: line 10, column 1
Can anyone suggest what I am doing wrong and/or a different way of doing it?
<apex:page controller="Graph2" > <apex:pageblock title="Grr!" > <apex:chart height="250" width="450" animate="true" data="{!pieData}"> <apex:axis type="Gauge" position="gauge" title="Transaction Load" minimum="10" maximum="400" steps="10"/> <apex:gaugeSeries dataField="data" donut="50" colorSet="#78c953,#ddd,#0F0" /> </apex:chart> </apex:pageblock> </apex:page>and this Controller:
public with sharing class Graph2 { public List<PieWedgeData> getPieData() { List<PieWedgeData> data = new List<PieWedgeData>(); List<Contact> memb = new List<Contact>(); // String sql = 'SELECT Name, Gauge_Value__c FROM Contact WHERE Id IN (SELECT contactid FROM user where id = :userinfo.getUserId())'; String sql = 'SELECT Name, Gauge_Value__c FROM Contact WHERE Gauge_Value__c != null'; memb = Database.Query(sql); for(Contact temp:memb) { data.add(new PieWedgeData(temp.Name,temp.Gauge_Value__c)); } return data; } // Wrapper class class PieWedgeData { public String name { get; set; } public Decimal data { get; set; } public PieWedgeData(String name, Decimal data) { this.name = name; this.data = data; } } }displays the chart just fine in the community (the user in question is the only one with a value in Gauge_Value__c), but as soon as I substitute in the commented out line which will return the results for the actual user, I get the following Visualforce Error:
System.QueryException: unexpected token: '('
Class.Graph2.getPieData: line 10, column 1
Can anyone suggest what I am doing wrong and/or a different way of doing it?
Try putting userinfo.getUserId() in a string and then use the string variable in the query.
Something like this,
String userId = userinfo.getUserId();
String sql = 'SELECT Name, Gauge_Value__c FROM Contact WHERE Id IN (SELECT contactid FROM user where id = :userId)';
Suggestion: you might want to add AccountId != null in the where clause of user query. From salesforce document.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm
Hope this helps.
Regards,
CloudSavvyProg
All Answers
Try putting userinfo.getUserId() in a string and then use the string variable in the query.
Something like this,
String userId = userinfo.getUserId();
String sql = 'SELECT Name, Gauge_Value__c FROM Contact WHERE Id IN (SELECT contactid FROM user where id = :userId)';
Suggestion: you might want to add AccountId != null in the where clause of user query. From salesforce document.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm
Hope this helps.
Regards,
CloudSavvyProg