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
uxtx_timuxtx_tim 

soql query based on user input

Im trying to figure out how to build soql queries based on user input.  For example a getter method called getChildren() will return a list of elements that have the selected element as a parent.  Should be pretty simple...

 

 

 public List<Element__c> getChildren(){
        return [select name,id  from Element__c where parent__c = the select field of the record I clicked];
    }

I tried giving an argument to the getter based on the value of an apex:param component like so:

 

 

VF:
<apex:param name="elementId" value="{!r.Signal_ID__c}"/>
<apex:dataList value="{!children({!$CurrentPage.parameters.elementId})}" var="c">
 {!c.name}
</apex:dataList>
Apex:
public List<Element__c> getChildren(PageReference thisRec){
return [select name,id,parent__c from Signal_Element__c where parent__c = thisRec];
}

But I get an error: unexpected token; 'thisRec' 

 

So I have two questions about this:

1.  How do I refer to a user selected element in a soql query?

 

2.  Why does the getter not seem to accept a an argument?

 

 

Pradeep_NavatarPradeep_Navatar

1.  To refer the selected element in soql query you have to pass the id of the selected element that should be appended with the element.  You can implement it by using ApexActionFunction.

 

2.  Logically getter do not accept any argument, it’s not a method even it looks like a method.

 

Write the : (column) before the “thisRec” in query like given below :

 

return [select name,id,parent__c from Signal_Element__c where parent__c =: thisRec];

uxtx_timuxtx_tim

Ahh ok - use the colon ( : ) character to refer to apex variable - thanks