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
DevAccountDevAccount 

Pass Standard controller output value to Extension controller Method's Soql

Hi,

     I am trying to Pass Standard controller output value to Extension controller Method's Soql. but its not passing the Parameter "RefID" to the extention controller Method's Soql where condition.

 

The soql works if I hard code the value in  where condition instead of parameter, like where TALLY_SHEET_REF__C = 'a005000000H1kcCAAR'

 

 

As you can see, I have red bolded the line that are not working..

 

 

My Visualforce page: (standardController="Tally_Sheets__c"  and  extensions="TallySheetItems")

 

<apex:page standardController="Tally_Sheets__c" extensions="TallySheetItems"  >
<apex:sectionHeader title="{!$ObjectType.Tally_Sheets__c.label}" subtitle="{!Tally_Sheets__c.name}"/>
<apex:pageBlock title="{!$ObjectType.Tally_Sheets__c.label} Header Detail">
<apex:pageBlockButtons location="top" >
<apex:form >
<apex:stylesheet value="{!$Resource.PacoriniCSS}"/>
<apex:commandButton action="{!edit}" value="Edit"/>
<apex:commandButton action="{!delete}" value="Delete"/>
<apex:commandButton action="{!URLFOR($Action.Tally_Sheets__c.Clone,Tally_Sheets__c.id)}" value="Clone"/>
</apex:form>
</apex:pageBlockButtons>
<table width="100%" >
<tr width="100%">
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="State:" />
<apex:outputField id="txtState" value="{!Tally_Sheets__c.State__c}"/>
</td>
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="Ref#:"/>
<apex:outputField id="Ref" value="{!Tally_Sheets__c.Name}"/>
<apex:param value="{!Tally_Sheets__c.Name}" name="RefID" id="RefID" />
</td>
</tr>
</table>

<apex:form >
<apex:outputPanel id="in" >
<apex:actionStatus startText="Updating...." id="outStatus">
<apex:facet name="stop">
<apex:dataTable value="{!TallySheetItems}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr" >
<apex:column headerValue="Ref#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tally_Sheet_Ref__c}" /></apex:column>
<apex:column headerValue="Melt#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.MELT__c}" required="false"/></apex:column>
<apex:column headerValue="Melt Date" ><apex:inputField style="width:100%; height:100%;" value="{!TSI.Melt_Date__c}" required="false"/></apex:column>
<apex:column headerValue="GR_WT_KG" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.GR_WT_KGS__c}" required="false"/></apex:column>
<apex:column headerValue="Tare" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tare__c}" required="false"/></apex:column>
</apex:dataTable>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:commandButton value="Submit" action="{!save}" />
<apex:commandButton value="Add" action="{!add}" rerender="in" status="inStatus" />
<apex:commandButton value="Reset" action="{!reset}" rerender="in,outStatus" status="outStatus" />
</apex:form>
</apex:pageBlock>
</apex:page>

 

My extensions Controller "TallySheetItems":

 

 

public class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

//added an instance varaible for the standard controller

public TallySheetItems(ApexPages.StandardController stdController)
{
this.controller=stdController;
}

List<Tally_Sheet_Item__c> TallySheetItemList;

public PageReference reset() {
TallySheetItemList= [select TALLY_SHEET_REF__C, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Tally_Sheet_Item_Ref__c from
Tally_Sheet_Item__c where TALLY_SHEET_REF__C = :ApexPages.currentPage().getParameters().get('RefID') limit 100 ];

return null;
}

public List<Tally_Sheet_Item__c> getTallySheetItems() {
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public void setTallySheetItems(List<Tally_Sheet_Item__c> TallySheetItems) {
TallySheetItemList = TallySheetItems;
}

public PageReference save() {
upsert TallySheetItemList;
return null;
}

public PageReference add() {
TallySheetItemList.add(New Tally_Sheet_Item__c());
return null;
}

}

 

 

 
Please let me where am I going wrong. or Let me know any other way to pass the value from the standardController.outputfiled value to the where condition on the extension controller. ( during the "reset" method is called on the extension controller. )


Look forward to your reply


Thanks

Arif

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Here, this example should help you....

 

CONTROLLER EXTENSION:

 

 

public with sharing class AccountExt {

Account a;
public AccountExt(ApexPages.StandardController controller) {
a = (Account) controller.getRecord();
}

public List<Contact> getContactsPassedThrough() {
return a.contacts;
}

public List<Contact> getContactsFromQuery() {
return [select name from contact where accountId = :a.id];
}

}

 

 

PAGE:

 

 

<apex:page standardController="Account" extensions="AccountExt">
<apex:pageBlock >
<apex:pageBlockSection columns="1" title="Account Detail Info">
<apex:outputField value="{!account.name}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Standard Controller (Direct)">
<apex:pageblockTable value="{!account.contacts}" var="c">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.email}"/>
<apex:column rendered="false">
{!c.description}
</apex:column>
</apex:pageblockTable>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Standard Controller (via Extension)">
<apex:pageblockTable value="{!contactsPassedThrough}" var="c">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.email}"/>
<apex:column value="{!c.description}"/>
</apex:pageblockTable>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Extension (Queried)">
<apex:pageblockTable value="{!contactsFromQuery}" var="c">
<apex:column value="{!c.name}"/>
</apex:pageblockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

 

 

All Answers

mtbclimbermtbclimber

can you describe at a high level what you want your page to do here? I don't think the solution involves any param passing here but I want to better understand what you are trying to accomplish as I'm hoping the solution is straight-forward.

 

DevAccountDevAccount

Hi mtbclimber,

 

Thanks for you quick response.

 

Basically I have 2 below objects

 

1. Tally Sheets__c

2. Tally_Sheet_Item__c has a look up feild "Ref#" looks up the "Tally Sheet.ID"

 

and my clients don't want the standard page layout look an feel for this particular page, so I went for Visual force page

 

In my Visual force page page tag


I use the standardController="Tally_Sheets__c" 

 

and extensions="TallySheetItems" where I wrote Soql on Tally_Sheet_Item__c and I want to put a condition saying where Tally_Sheet_Item__c . TALLY_SHEET_REF__C = Tally Sheet . ID to get only the related records by passing the value form the below outputField from the visualforce page.

<apex:outputField id="Ref" value="{!Tally_Sheets__c.ID}"/>

 

Hope you understand my situation.

 

Thanks

Arif

 

mtbclimbermtbclimber

Ok. So what happens if you change this line in your page:

 

 

<apex:dataTable value="{!TallySheetItems}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr"  >

 

 

To this:

 

 

<apex:dataTable value="{!Tally_Sheets__c.Tally_Sheet_Items__r}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr"  >

 Assuming the ChildRelationthip Name for your reference field on tally sheet item that points back to tally sheets is "Tally_Sheet_Items".  This is the field you've called "Ref#" it seems.

 

This does what I think you are after.

 

 

 

DevAccountDevAccount

Your suggestion works but my in my I want have lot of other logics by using the my Extension controller

 

In below datatable calls the Extension controller "TallySheetItems" which I can't remove because that supports other add reset and other commands. 

 

 

<apex:dataTable value="{!TallySheetItems}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr"  >

 

Please let me know, How to pass the below output field value to the Extension controller "TallySheetItems"

 

<apex:outputField id="Ref" value="{!Tally_Sheets__c.Name}"/>

 

I would really appreciate your help on this.

 

Thanks

Arif

mtbclimbermtbclimber

Unless you need to filter or order the items in fact you don't need to issue the query at all in your extension.

 

And frankly, I don't understand the purpose of passing that value to your extension even if you do need to do the query. The value you want to "pass" is not changing (i.e. there is no input element where the user changes it) and in fact it's already in the object passed to the extension automatically and by the way if you're using a lookup field or master/detail relationship for the Tally_Sheet_Ref__c field you want to filter on the ID field of the tally_sheets__c object, not its name.

DevAccountDevAccount

I completly understand your point and appreciate your patience in explaining me.

 

If there is a way, please let me know how to pass this outputvalue to the Extension. Because for not only this context, I might need to use it for filtering in future.

 

Thanks and Appreciate your help on this.

Arif

mtbclimbermtbclimber

Here, this example should help you....

 

CONTROLLER EXTENSION:

 

 

public with sharing class AccountExt {

Account a;
public AccountExt(ApexPages.StandardController controller) {
a = (Account) controller.getRecord();
}

public List<Contact> getContactsPassedThrough() {
return a.contacts;
}

public List<Contact> getContactsFromQuery() {
return [select name from contact where accountId = :a.id];
}

}

 

 

PAGE:

 

 

<apex:page standardController="Account" extensions="AccountExt">
<apex:pageBlock >
<apex:pageBlockSection columns="1" title="Account Detail Info">
<apex:outputField value="{!account.name}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Standard Controller (Direct)">
<apex:pageblockTable value="{!account.contacts}" var="c">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.email}"/>
<apex:column rendered="false">
{!c.description}
</apex:column>
</apex:pageblockTable>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Standard Controller (via Extension)">
<apex:pageblockTable value="{!contactsPassedThrough}" var="c">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.email}"/>
<apex:column value="{!c.description}"/>
</apex:pageblockTable>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Contacts from Extension (Queried)">
<apex:pageblockTable value="{!contactsFromQuery}" var="c">
<apex:column value="{!c.name}"/>
</apex:pageblockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

 

 

This was selected as the best answer
DevAccountDevAccount

This is what I exactly wanted.

Thank you very much for your help.