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
geetageeta 

issue with apex:page action

Hi,

 

I have a Visualforce page that calls init() function at the page level like below:

<apex:page standardController="Volunteer_Activity__c" action="{!init}" title="Volunteer Activity: {!Volunteer_Activity__c.Name}" extensions="VolActivityMassSignUpControllerExt">

 

In my controller init() function when I try to get an attribute (Total_Number_of_Participants__c) of the Volunteer_Activity object, I get a null. Here is how my controller class looks like:

 

public class VolActivityMassSignUpControllerExt {

   private Volunteer_Activity__c va;

  

   public VolActivityMassSignUpControllerExt(ApexPages.StandardController stdController) {        this.va = (Volunteer_Activity__c) stdController.getRecord();

 

      System.debug(Logginglevel.DEBUG, 'Constructor ' + va.Id);

   }

 

   public void init() {

      id = va.Id;

      name = va.Name;

 

 

      Double totalParticipants = va.Total_Number_of_Participants__c; 

      ---

      ---

   }

 

To resolve this, I am explicitly doing a query to retrieve the object. Did anyone experience this issue? Can you please help?

 

Thanks,
Geeta

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

First of all, directly from the documentation for the action attribute on apex: page:

 


This action should not be used for initialization.

You are saying that your Total_Number_of_Participants__c has a value at load time, and your id and name are non null but the number of participants is null?  That seems strange.

 

Regardless the first thing you need to do is get rid of your page level action and instead call init() inside of your extension constructor.  I doubt this will get rid of your issue but it's good practice anyway.  What references do you have on your page to the Total_Number_of_Participants field?

All Answers

jwetzlerjwetzler

First of all, directly from the documentation for the action attribute on apex: page:

 


This action should not be used for initialization.

You are saying that your Total_Number_of_Participants__c has a value at load time, and your id and name are non null but the number of participants is null?  That seems strange.

 

Regardless the first thing you need to do is get rid of your page level action and instead call init() inside of your extension constructor.  I doubt this will get rid of your issue but it's good practice anyway.  What references do you have on your page to the Total_Number_of_Participants field?

This was selected as the best answer
geetageeta

Thanks Jill. I changed it as per your suggestion and it works fine now.