1

Vf code:

<apex:page controller='autocall'>
    <div align='center'>
        {!msg}
    </div>
</apex:page>

Apex code:

public class autocall
{
    public string msg {get;set;}
    public void callme()
    {
        msg='hello world';
    }
}

so, how do I call 'autocall()' method automatically when above vf page loads. please help me thanks in advance.

1 Answer 1

2

You can call the apex method on load via apex:page's action attribute:

The action method invoked when this page is requested by the server. Use expression language to reference an action method. For example, action="{!doAction}" references the doAction() method in the controller. If an action isn’t specified, the page loads as usual.

Important: Do not use this action for initialization or DML.

<apex:page controller='autocall' action='{!callme}'>
    <div align='center'>
        {!msg}
    </div>
</apex:page>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .