You need to sign in to do that
Don't have an account?
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.
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.
This may be what you are looking for:
http://force201.wordpress.com/2010/08/26/executing-some-controller-code-before-a-default-page-is-displayed/