0

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.

New contributor
Harish Rudroju is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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>

Your Answer

Harish Rudroju is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.