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}">

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();'acc'+i;
     insert acclist;
      return null;
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');
           return pg;