You need to sign in to do that
Don't have an account?

Passing A Parent Object Field Value When Editing Child Record
Hello. I was wondering if anyone could give me some guidance to the below issue. Thanks in advance.
I have two objects
1) TransactionCategory__c contains details about transaction categories.
2) Transactions__c contains individual transactions by customers.
* TransactionCategory__c is the parent of Transactions__c.
I am developing an edit page for new Transactions__c records. This page will collect details about each transaction.
The Transactions_c page contains a picklist of transaction categories - so each transaction can be tied to a specific TransactionCategory__c.
Certain TransactionCategory__c records have a Risk__c field value of "true". These are risky transactions that need to be more thoroughly documented than other transactions.
My desire is to gather this needed additional risky Transaction__c information in an additional outputPanel - but I only want to show this outputPanel for those TransactionCategory__c records with a Risk__c value of "true". Otherwise, I do not want to display the outputPanel.
Unfortunately, I have yet to be able to pass a valid value of the Risk__c field based on the TransactionCategory__c record choice selection (as selected by TransTypeChoices).
I have tried modifying the actionSupport, using a param, creating a list, etc, etc, etc - in order to pass the Risk__c value...but nothing seems to work.
Any thoughts would definitely be appreciated. Below is the relevant VF and controller code.
VF PAGE // a list of transaction types are provided via a picklist <apex:pageblockSectionItem > <apex:outputLabel value="Transaction Category:" for="TransCat"/> <apex:selectList id="TransCat" value="{!NewTrans.TransactionCategory__c}" size="1" title="Menu"> <apex:selectOptions value="{!TransTypeChoices}"> </apex:selectOptions> <apex:actionSupport event="onchange" rerender="AdditionalInfo"> </apex:actionSupport> </apex:selectList> </apex:pageblockSectionItem> // The below section should only be displayed when the TransactionCategory__c's Risk__c value = true. // Unfortunately, this is not working as desired. <apex:outputPanel id="AdditionalInfo"> <apex:outputPanel rendered="{NewTrans.TransactionCategory__r.Risk__c = true}"> <apex:inputField value="{!NewTrans.AddQuestion1__c}" id="Add1"/> <apex:inputField value="{!NewTrans.AddQuestion2__c}" id="Add2"/> <apex:inputField value="{!NewTrans.AddQuestion3__c}" id="Add3"/> </apex:outputPanel> </apex:outputPanel> CONTROLLER // Creating a new Transaction__c record public Transactions__c NewTrans { get { if (NewTrans == null) NewTrans = new Transactions__c(); return NewTrans; } set; }
try changing
<apex:outputPanel rendered="{NewTrans.TransactionCategory__r.Risk__c = true}">
to
<apex:outputPanel rendered="{!IF(NewTrans.TransactionCategory__r.Risk__c = true, True,False)}">
Thanks for the suggestion...but it still does not work.
I was wondering if the issue was because the Risk__c field is not referenced anywhere on the page. In other words, nothing is currently being done to get the Risk__c value from the controller. I wondered whether creating a LIST using ApexPages would suffice...but I had no luck with that either.
When you made the change, did the panel display or not?
Try adding a variable to the controller that pulls the Risk__c from the related record and use that in the reddered statement.
What if you added the rendered to the first output panel with the ID?
I think that since you are createing a new record it is not related to any parent. If you sent the value of the relationship link to an existing record then the rendered statement should work without declaring the variable.
What does the field say when you just print it out to the screen? That would be my first step to debug is just find out if you're getting the field as you expect or not? Then you can move on to figuring out if you want to conditionally display the panel...
Yes, I have tested things extensively. I know the re-rendering logic works because I hard-coded a couple of ids - and all works fine. However, I was never able to expose the Risk__c field (I tested to see if I could simply display the Risk__c value - and it never worked.
Given all of that, I am basically trying to see how I can get the Risk__c value...once I am able to see the value, all should be fine.
Thanks again.
I just read and re-read your original post. I THINK - (I could be wrong but...) - you need to query for the Risk__c field once the Transaction Category is selected. Otherwise, how will the controller know what value is in Risk?
Depending on how many Transaction Categories there are, this could take a bit of time. You could optionally pre-populate all the Transaction Categories and associated Risks into a selectList on page load, which is maybe what you've done here?
Thanks for the thoughts.
After rereading your post I am a bit confused so please let me know if I am understanding:
1. 2 Object - TransactionCategory and Transactions
2. TransactionCategory is the parent of Transactions (on master-Detal relationship where transactions is the child?)
3. You are using a picklist on the transactions that has the transactionCategory names in it.
4. The Risk__c is on the TransactionCategory related object
if this is the case you can get to the Risk__c via {!newTrans.**put field name that links to the parent here**__r.Risk__c}
example:
Object A - Parent
Object B - Child
Risk__c is on object A
Field ObjectA is the master-detail link on Object B
to get to risk I would use {!newTrans.ObjectA__r.Risk__c}
now, if you have no master detail link, you would have to take the value selected from the picklist, then populate a list of TransactionCategory with a name that = the value from the picklist limit 1, then access the risk__c of that list.
If the link to the parent is through a lookup, you will have to set the value of the lookup when you create NewTrans on the controller before you can access Risk__c
The problem I see though is that in this case, what if they pick a different transactioncategory from the picklist that what the master record is?
Maybe I am reading you original post wrong, I will read closer and edit this post if needed.
What is you pass the value of the selectlist from the vf page using java and action:function to the controller
in the controller access the parameter passed
then create a list that returns all transactioncategory records with type = passed value
set the render = the value of Risk__c in the list
I will outline a bit below:
(not in order they need to be on the page or controller)
Page
apex:SelectList id="uSelect"" ......... onchange="pValue()"
apex:actionFunction name="myPassedValue" action="{!cList}" rerender="additionalData"
apex:param name="myParam" value = " " / assignTo="{!VarA}"
/apex:actionFunction
<script>
function pValue(){
var a = document.getElementById('{!$Component.uSelect}').value;
myPassedValue(a)
}
</script>
Controller
Public List<TransactionCategory> tmpList;
Public String VarA;
public cList(){
tmpList = [Select id, name__c , Risk__c From TransactionCategory__c Where name =: VarA limit 1];
}
Then in the rendered section of that pageblock or whatever you could add the IF({!tmpList.Risk__c}=True,True,False)
Just babbling, maybe it will help. Basically you need to find a trans category based of a value selected on the page so you need to pass it. Since there is only 1 trans category record you can get it using list and pull the risk__c value from it.
Thanks for the help. This makes sense.
I have run into a related issue (which I am posting separately)...but this was definitely helpful.