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
kdmrkdmr 

How to pass value to a query

Hi All, I have a question, I am trying to create a query to be passed to the datatable based on a value from VisualForce UI, though the query compiles it takes the value as null. for eg. the query line is similar to

object2list = [select id, name, field1__c, field2__c from Object2 where object1__c =: paramval];

1. Object1__c is a related to Object2.

2.paramval is the value passed to the controller from the UI using the apex:param tag.

3. query produces table taking the paramval to be null

4. If I substitue it with the Id the query returns proper data table.

5. If I use the paramval else where and it takes the value properly and am able to save it too.

I am trying to do this so that I can have dependent lookup, the value of paramval will be the id for the value choosen for Object1__c.

Thanks

KD 

Best Answer chosen by Admin (Salesforce Developers) 
kdmrkdmr

The issue is resolved, it was a problem in the rerender in the vf codes. Was able to fix it and get it working.

Thanks

KD 

All Answers

KevinLaurenceKevinLaurence

Looks to me like a misplaced space in your SOQL query. Try the following instead:

 

select id, name, field1__c, field2__c from Object2 where object1__c = :paramval

 

There should be a space between the equal sign and the colon, but no space between the colon and the variable name. 

 

KML 

kdmrkdmr

Checked it, it is as you say a space between the equals and the colon and no space between the colon and the parameter. It seems to be much more than the issue with the space. But thanks for the info provided.

KD 

SteveBowerSteveBower

Post more code.  Where are you getting paramval from?    It doesn't make sense if you say it doesn't work here, but it works elsewhere.

 

The other possibility is that your query is returning null because there *are* no Object2 records that are linked to the Object 1 you are passing in.  Check your data.

kdmrkdmr

Hi Steve,

I am attaching both the VF and the controller code.

The VF code is 

<apex:page standardController="Object3__c" extensions="lookup">

<apex:stylesheet value="http://yui.yahooapis.com/2.6.0/build/assets/skins/sam/skin.css" />

<apex:includescript value="http://yui.yahooapis.com/2.6.0/build/yahoo-dom-event/yahoo-dom-event.js" />

<apex:includescript value="http://yui.yahooapis.com/2.6.0/build/dragdrop/dragdrop-min.js" />

<apex:includescript value="http://yui.yahooapis.com/2.6.0/build/container/container-min.js"/>

<apex:includescript value="http://yui.yahooapis.com/2.6.0/build/animation/animationmin.js"/>

<script>

YAHOO.namespace("force.com");

YAHOO.force.com.showob1 = function() {

document.getElementById("myob1").style.display = "block";YAHOO.force.com.myob1.show();

}

YAHOO.force.com.showob2 = function() {

document.getElementById("myob2").style.display = "block";YAHOO.force.com.myob2.show();

}

YAHOO.force.com.hideob1 = function() {

YAHOO.force.com.myob1.hide();

}

YAHOO.force.com.hideob2 = function() {

YAHOO.force.com.myob2.hide();

}

YAHOO.force.com.init = function() {

document.body.className = document.body.className + " yui-skin-sam";

YAHOO.force.com.myob1 = new YAHOO.widget.Panel (

"myob1",

{

width : "300px",

visible : false,

height : "150px"

,xy : [350,50],

draggable : true,

close : true,

modal : true,

//fixedCenter : true,

zindex : 40,

effect : {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.35}

}

);

YAHOO.force.com.myob1.render(document.body);

YAHOO.force.com.myob2 = new YAHOO.widget.Panel (

"myob2",

{

width : "300px",

visible : false,

height : "150px",

xy : [350,50],

draggable : true,

close : true,

modal : true,

//fixedCenter : true,

zindex : 40,

effect : {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.35} }

);

YAHOO.force.com.myob2.render(document.body);

YAHOO.util.Event.addListener(window, "load", YAHOO.force.com.init);

</script>

<apex:sectionHeader title="Asset Update Edit" subtitle="New Asset Update"/>

<apex:outputPanel>

<apex:form id="form1">

<apex:pageBlock id="pb1">

<apex:pageBlockSection id="pbs1" columns="2">

<apex:pageBlockSectionItem id="pbsi1">

<apex:outputLabel for="ob1" value="Object1"/>

<apex:outputPanel ><div class = "requiredInput">

<div class = "requiredBlock"/>

<apex:inputText value="{!paramval}" required="true" id="ob1"/>

<apex:image styleclass="lookupIcon" id="ob1image" onclick="YAHOO.force.com.showob1();" value="/s.gif"/>

</div>

</apex:outputPanel>

</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="pbsi2">

<apex:outputLabel for="ob2" value="Object2"/>

<apex:outputPanel>

<apex:inputText value="{!param1val}" id="ob2"/>

<apex:image styleclass="lookupIcon" id="ob2image" onclick="YAHOO.force.com.showob2();" value="/s.gif" />

</apex:outputPanel>

</apex:pageBlockSectionItem>

</apex:pageBlockSection>

<apex:pageBlockButtons>

<apex:commandButton value="Save" action="{!save}"/>

<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlockButtons>

</apex:pageBlock>

</apex:form>

</apex:outputPanel>

<div id="myob1" style="display: none">

<div class="hd">

<apex:outputText value="Object1" />

</div> <div class="bd" style="overflow:auto; background-color:fff;padding:10px;">

<apex:form id="form2">

<apex:dataTable value="{!obj1s}" var="o1" cellPadding="4" border="1" id="obj1table">

<apex:column headervalue="Object1 Name"><apex:commandLink oncomplete="YAHOO.force.com.hideob1();" rendered="true" reRender="ob1">

{!o1.Name}

<apex:param name="o1name" assignTo="{!paramval}" id="obj1name" value="{!o1.Name}"/>

<apex:param name="o1id" assignTo="{!paramid}" id="obj1id" value="{!o1.Id}"/>

</apex:commandLink>

</apex:column>

</apex:dataTable>

<apex:commandButton value="Cancel" immediate="true" oncomplete="YAHOO.force.com.hideob1();"/>

</apex:form>

</div>

</div>

<div id="myob2" style="display: none">

<div class="hd">

<apex:outputText value="Object2" />

</div>

<div class="bd" style="overflow:auto; background-color:fff;padding:10px;">

<apex:form id="form3">

<apex:dataTable value="{!obj2s}" var="o2" cellPadding="4" border="1" id="obj2table">

<apex:column headervalue="Obj2 Names"><apex:commandLink oncomplete="YAHOO.force.com.hideob2();" rendered="true" reRender="ob2">

{!o2.Name}

<apex:param name="ob2name" assignTo="{!param1val}" id="obj2name" value="{!o2.Name}"/>

<apex:param name="ob2id" assignTo="{!param1id}" id="obj2id" value="{!o2.Id}"/>

</apex:commandLink>

</apex:column>

</apex:dataTable>

<apex:commandButton value="Cancel" immediate="true" oncomplete="YAHOO.force.com.hideo2();"/>

</apex:form>

</div>

</div>

</apex:page>

 The controller code is

 

public class lookup {

Object2__c obj2;

Object1__c obj1;

Object3__c obj3;

List<Object1__c> obj1list;

List<Object2__c> obj2list;

List<Object3__c> obj3list;

public lookup (ApexPages.StandardController stdcont) {

this.obj3 = (Object3__c)stdcont.getRecord();

}

public string paramid, paramval, param1id, param1val;

public string getparamid() { return this.paramid; }

public void setparamid(string el) { this.paramid = el; }

public string getparamval() { return this.paramval; }

public void setparamval(string el) { this.paramval = el; }

public string getparam1id() { return this.param1id; }

public void setparam1id(string el) { this.param1id = el; }

public string getparam1val() { return this.param1val; }

public void setparam1val(string el) { this.param1val = el; }

public List<Object1__c> getobj1s() {

obj1list = [select Id, Name from Object1__c];

return obj1list;

}

public List<Object2__c> getobj2s() {

obj2list = [select Id, Name from Object2__c where Object1__c = :paramid];

return obj2list;

}

public pagereference save() {

obj3list = new List<Object3__c>();

obj3list.add(new Object3__c(Object1__c = paramid, Object2__c = param1id));

insert obj3list;

pagereference savepage = new pagereference('/' +paramid);

savepage.setredirect(true);

return savepage;}

}

 when passing the paramid to the list query, it takes the value as null and returns list that have a null value for that field. But when doing the save function it returns the proper value.

 

Thanks

KD 

 

 

 

Message Edited by kdmr on 06-07-2009 11:06 PM
kdmrkdmr

The issue is resolved, it was a problem in the rerender in the vf codes. Was able to fix it and get it working.

Thanks

KD 

This was selected as the best answer