Find your content:

Search form

You are here

How to include data from custom Lookup Relationships in a Visualforce page

 
Share

I have a custom object: License, this has a Lookup for the standard Account (meaning: an account can have many licenses) and they are shwon on the account page with a related list.

On my account page, there is a custom field called: Support_end_date

I want that if anyone is accessing the License page, a pop up will show if the account is not under support. (first part is working, as for SF question: How to compare 2 dates in JavaScript on a Visualforce page?)

My current code than is:

<apex:page StandardController="OptiTex_License__c">
 <script>
window.document.onload = new function(e)
{
  var tempdate = new Date("{!OptiTex_License__c.Account.Support_end_date__c}");

  if(tempdate < Date.now() || tempdate ){
    alert("--- ATTENTION --- \nCustomer is NOT under Support\nor no support end date is given.");
  }
}
</script>

</apex:page>

*Similar code, only that the StandardController is now the customer: License object.

I tried to access the Account field through: OptiTex_License__c.Account.Support_end_date__c - but that gave me a compilation error.

So I ask: How and where in my code to I query (SOQL maybe?) or simply have access to the values from my parent.


Attribution to: Saariko

Possible Suggestion/Solution #1

Your code is almost correct. The error is the way you are trying to access the support date.

Where you are referencing the Account relationship you actually trying to access a custom field via a custom relationship you have created.

So you need to use the __r notation:

OptiTex_License__c.Account__r.Support_end_date__c

If your relationship was a customfield called MyAccountLink you would reference the actual Id of the relationship using MyAccountLink__c but to access information within that object MyAccountLink__r.MyAccountCustomField__c

For more information please read this page on the relationship notation that Apex and SOQL use: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm

This should give you:

<apex:page StandardController="OptiTex_License__c">
 <script>
window.document.onload = new function(e)
{
  var tempdate = new Date("{!OptiTex_License__c.Account__r.Support_end_date__c}");

  if(tempdate < Date.now() || tempdate ){
    alert("--- ATTENTION --- \nCustomer is NOT under Support\nor no support end date is given.");
  }
}
</script>

</apex:page>

Attribution to: Jon Hazan
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/503

My Block Status

My Block Content