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
ch ranjeethch ranjeeth 

I want to insert records when the page is reloading...i have written some code but its working with when i saving the page.Need help to wtire this code

<apex:page controller="Recordinsertion" action="{!method}">
 
</apex:page>

Controller:
public with sharing class Recordinsertion {

    public PageReference method()
     {
         list<account> acclist=new list<account>();
         for(integer i=50;i<80;i++)
         {
        
         account a=new account();
         a.name='acc'+i;
         acclist.add(a);
       }
     insert acclist;
      return null;
   }
}
bob_buzzardbob_buzzard
Can you explain what you mean by 'when the page is reloading'?  You have written an action method and that can only be called from a couple of places - to handle a form postback or before the page is rendered.
ch ranjeethch ranjeeth

when i refreshing the page it should insert some records in account its my scenario......
Mani RenusMani Renus
Your returnign null after saving i think you want to redirect the particular page,If my guess is correct then follow

Instead of 'retrun null;'  you can use below code

PageReference pg = new PageReference('/a00/o'); //Here in parameters you have to give your object path or
//PageReference pg = new PageReference('/apex/PageName');
         pg.setRedirect(true);
           return pg;


Cheers
Mani