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
jblon1973jblon1973 

Invalid bind expression type of Schema.SObjectField for column of type Id

I am getting the named error on the following code. I am not sure what I am missing.

 

The structure is that the Trial__c is the parent of Trial_Data__c and I am simply trying to query all the Trial Data related to one trial.

 

Here is my Code:

for(Trial_Data__c td : [Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c =: Trial__c.Id ORDER BY Id ASC])
        	{                                                          
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( td.Channel_Volume__c));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }

 The error is on the first row query. I need to make sure I am not pulling ALL Trial_Data__c records to display.

 

Thank you for any help you can provide.

 

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu
For line 5:

strTrial = ApexPages.currentPage().getParameters().get('Id');

All Answers

AmitSahuAmitSahu
You did not specify the line number .. But can you please try the query :
[Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c =: Trial__c.Id ORDER BY Id]

or

[Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c =: Trial__c.Id ]
jblon1973jblon1973

The error is in the select statement.

 

Unfortunately, the queries produce the same error.

AmitSahuAmitSahu
The problem is with Trial__c.Id in the query.

Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c =: Trial__c.Id ORDER BY Id ASC

use some variable to store the Trial__c.Id value and use it in query.

example:

String x = Trial__c.Id ;

then in query use it :

Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c =:x ORDER BY Id ASC
jblon1973jblon1973

That produces the error of:

 

Illegal Assignment from Schema.SObjectField to String.

AmitSahuAmitSahu
Please provide the complete code other wise I am not sure where you are capturing the id .. If you dont have a proper id this will trow error
jblon1973jblon1973

Here is the complete code and it is on line 19

public with sharing class TestResultGraphConroller {

  
    public TestResultGraphConroller(ApexPages.StandardController stdController){
    }
    
    
    public String getTimeVolume(){
        return getTimeVolume(null);
    }
    
    public String getTimeVolume(List<Id> ids){
    	GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
Line 19-> for(Trial_Data__c td : [Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c = :Trial__c.Id  ORDER By Id ASC ])
        	{                                                          
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( td.Channel_Volume__c));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }

        return gv.toJsonString();
    }  
    
//    private testMethod static void testTestResult(){
//       String expected = '{cols: [{id: "col1", label: "Interval", type: "number"},{id: "col2", label: "Channel Flow", type: "number"},{id: "col3", label: "Channel Volume", type: "number"}]}';
//        
//        Test__c t1 = new Test__c();
//        insert t1;
//        Trial_Data__c td1 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00125, Channel_Volume__c=0.14526);
//        Trial_Data__c td2 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00250, Channel_Volume__c=0.15128); 
//        insert new List<Trial_Data__c> {td1, td2};
//             
//    }
    public String getFlowVolume(){
        return getFlowVolume(null);
    }
    
    public String getFlowVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col1','Channel Volume','number'),
            new GoogleViz.col('col2','Channel Flow','number')    
            };              
               
        for(Trial_Data__c td : [Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c
                    From Trial_Data__c WHERE Trial__c = :Trial__c.Id
                    ORDER BY Id ASC]){//Database.query(query)){ - OLD LOGIC 
                                                          
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( td.Channel_Volume__c));//X-Axis
            r.cells.add ( new GoogleViz.cell( td.Channel_Flow__c));//interval
            gv.addRow( r ); 
            }

        return gv.toJsonString();
    }  
    
//    private testMethod static void testTestResult(){
//       String expected = '{cols: [{id: "col1", label: "Interval", type: "number"},{id: "col2", label: "Channel Flow", type: "number"},{id: "col3", label: "Channel Volume", type: "number"}]}';
//        
//        Test__c t1 = new Test__c();
//        insert t1;
//        Trial_Data__c td1 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00125, Channel_Volume__c=0.14526);
//        Trial_Data__c td2 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00250, Channel_Volume__c=0.15128); 
//        insert new List<Trial_Data__c> {td1, td2};
//             
//    }
    
}

 

AmitSahuAmitSahu
Are you using this as a controller on VF page ?
jblon1973jblon1973
Yes I am
jblon1973jblon1973

Yes I am. It displays a Visualization

AmitSahuAmitSahu

If your page is getting any id then it might work:

 

public with sharing class TestResultGraphConroller {
public strTrial;
  
    public TestResultGraphConroller(ApexPages.StandardController stdController){
	strTrial = ApexPages.currentPage.getParameter().get('id');
    }
    
    
    public String getTimeVolume(){
        return getTimeVolume(null);
    }
    
    public String getTimeVolume(List<Id> ids){
    	GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
        for(Trial_Data__c td : [Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c From Trial_Data__c WHERE Trial__c = :strTrial  ORDER By Id ASC ])
        	{                                                          
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( td.Channel_Volume__c));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }

        return gv.toJsonString();
    }  
    
//    private testMethod static void testTestResult(){
//       String expected = '{cols: [{id: "col1", label: "Interval", type: "number"},{id: "col2", label: "Channel Flow", type: "number"},{id: "col3", label: "Channel Volume", type: "number"}]}';
//        
//        Test__c t1 = new Test__c();
//        insert t1;
//        Trial_Data__c td1 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00125, Channel_Volume__c=0.14526);
//        Trial_Data__c td2 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00250, Channel_Volume__c=0.15128); 
//        insert new List<Trial_Data__c> {td1, td2};
//             
//    }
    public String getFlowVolume(){
        return getFlowVolume(null);
    }
    
    public String getFlowVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col1','Channel Volume','number'),
            new GoogleViz.col('col2','Channel Flow','number')    
            };              
               
        for(Trial_Data__c td : [Select Id, Channel_Volume__c, Channel_Flow__c, Trial__c
                    From Trial_Data__c WHERE Trial__c = :Trial__c.Id
                    ORDER BY Id ASC]){//Database.query(query)){ - OLD LOGIC 
                                                          
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( td.Channel_Volume__c));//X-Axis
            r.cells.add ( new GoogleViz.cell( td.Channel_Flow__c));//interval
            gv.addRow( r ); 
            }

        return gv.toJsonString();
    }  
    
//    private testMethod static void testTestResult(){
//       String expected = '{cols: [{id: "col1", label: "Interval", type: "number"},{id: "col2", label: "Channel Flow", type: "number"},{id: "col3", label: "Channel Volume", type: "number"}]}';
//        
//        Test__c t1 = new Test__c();
//        insert t1;
//        Trial_Data__c td1 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00125, Channel_Volume__c=0.14526);
//        Trial_Data__c td2 = new Trial_Data__c(Test__c = t1.Id, Interval__c=0.01, Channel_Flow__c=3.00250, Channel_Volume__c=0.15128); 
//        insert new List<Trial_Data__c> {td1, td2};
//             
//    }
    
}

 

jblon1973jblon1973

That gives me unexpected token ";" on line 2

AmitSahuAmitSahu
ohh sorry please replace line #2 with this :

public string strTrial;
jblon1973jblon1973

Now I am getting this error:

 

Method does not exist or incorrect signature: ApexPages.currentPage.getParameter()TestResultGraphConroller.cls/TechEd Production/src/classesline 5

AmitSahuAmitSahu
For line 5:

strTrial = ApexPages.currentPage().getParameters().get('Id');
This was selected as the best answer
jblon1973jblon1973

Thank you so much. It works!!!!

 

JP

AmitSahuAmitSahu
Sorry for the time taken ... was not aware of the actual code and context ... :)
tselvamtselvam

I thing you using Schema.SObjectField to query the relatioship object.So it will throw an error