You need to sign in to do that
Don't have an account?
iceberg4u
how do i make a query statement dynamic
my controller class
public class NewOne
{
List<ContactUs__c> a=new List<ContactUs__c>();
public NewOne()
{
a=[select name,lastName__c from ContactUs__c];
}
public void sort1()
{
String val=System.currentPageReference().getParameters().get('st'); //m trying to pass the name of the custom field
System.debug('-------------------------------------------------------------');
System.debug('the value that i have is:'+val);
System.debug('-------------------------------------------------------------');
a=[select name,lastName__c from ContactUs__c order by val asc];
}
public List<ContactUs__c> getDataValue()
{
return a;
}
}
how do i use this "val" that stores a custom field like name,lastname__c in querying or for that matter just accessing data.
smthn like:- ContactUs__c a1=new ContactUs__c();
a."val"=XXX;
how do i use this val ??
from my page i have passed
<apex:outputText value="firstname"/>
<apex:actionSupport event="onclick" action="{!sort1}" rerender="tb">
<apex:param name="st" value="name"/>
</apex:actionSupport>
public class NewOne
{
List<ContactUs__c> a=new List<ContactUs__c>();
public NewOne()
{
a=[select name,lastName__c from ContactUs__c];
}
public void sort1()
{
String val=System.currentPageReference().getParameters().get('st'); //m trying to pass the name of the custom field
System.debug('-------------------------------------------------------------');
System.debug('the value that i have is:'+val);
System.debug('-------------------------------------------------------------');
a=[select name,lastName__c from ContactUs__c order by val asc];
}
public List<ContactUs__c> getDataValue()
{
return a;
}
}
how do i use this "val" that stores a custom field like name,lastname__c in querying or for that matter just accessing data.
smthn like:- ContactUs__c a1=new ContactUs__c();
a."val"=XXX;
how do i use this val ??
from my page i have passed
<apex:outputText value="firstname"/>
<apex:actionSupport event="onclick" action="{!sort1}" rerender="tb">
<apex:param name="st" value="name"/>
</apex:actionSupport>
You can't use a variable in the order by clause unless you convert to fully dynamic SOQL. Another major missing feature.
Here's what you'd have to do: