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
lvivaninlvivanin 

Action function on <apex:page>

I am trying execute action when the page loads. I want to display the details of a record Id (for testing purposes i have hardcoded the Id).

 

public class MileageExtension {
private final Mileage__c mileageObj;
public MileageExtension(ApexPages.StandardController controller) {
this.mileageObj = (Mileage__c)controller.getRecord();
}
public Mileage__c[] getTodaysMileageRecords() {
String createdbyId = UserInfo.getUserId();
Mileage__c[] mileageList =
[SELECT name, miles__c
FROM Mileage__c
WHERE Date__c <= TODAY
AND createdbyid = :createdbyId];
return mileageList;
}

public PageReference InitMileageCustomview() {
PageReference secondPage = Page.MileageCustomview;
secondPage.setRedirect(true);
secondPage.getParameters().put('id','a008000000CqtDd');
return secondPage;

}

}

 And My Page is

 

 

 

<apex:page standardController="Mileage__c" extensions="MileageExtension" action="{!InitMileageCustomview}">
<h1>{!$User.FirstName}'s Mileage Page</h1>
<apex:pageBlock >
<apex:pageBlockSection title="Today’s Mileage Records">
<apex:dataTable value="{!TodaysMileageRecords}"
var="mileage" styleClass="list">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!mileage.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Miles</apex:facet>
<apex:outputText value="{!mileage.Miles__c}"/>
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:detail subject="{!Mileage__c.Contact__c}" relatedList="false"/>
</apex:page>

 

 

 

When I click the visualforce tab it keeps running and running (infinite loop....).  How can I get the detail record whenever the page gets loaded?

 

Thank you.

 

 

 

 

TehNrdTehNrd
There is no need for an action method in your page. If you are using the standard controller and are passing the Id attribute you don't even need the query as you can access values my using merge syntax {!Milage__c.SomeField}.
Message Edited by TehNrd on 07-28-2009 10:04 AM
lvivaninlvivanin

It loads Mileage Records. I am trying to get the related contact detail (i am hardcoding ContactID for demo purpose) record of a specific Mileage Record  also be populated when I click the visualforce page.

 

<apex:detail subject="{!Mileage__c.Contact__c}" relatedList="false"/>

 

Rajesh ShahRajesh Shah
In the InitMileageCustomView function, you are redirecting the user back to the MileageCustomView page. The page gets loaded again which again calls the InitMileageCustomView function. Hence the infinite loop.