+ Start a Discussion

Need apex coding help

Hi My requirement is like this,


First get all  the account  which are created  last 7 days.



Create new contact if  they are not having contact. address from contact



Then  shedule that  in hourly basis....


How to dothat..


Please let me know ......It would be a great help for me.....


This can be done in two ways.

1. You can create a batch apex and write a schedular to invoke this batch job for every one hour



2. You can make use of cronkit and write a class and invoke this class with the help of cronkit trigger.




Hi  Thanks for reply ..



Itried the sheduling class but its not working..kindly elaborate  with some sample



You can use Apex Scheduler to schedule a controller to execute it on a regular basis at certain given time in future.


For this you have to make a Controller and to schedule this controller go to Administration Setup->Monitoring->Scheduled Jobs


from there select the Controller and provide some time and date to execute.


Find below a sample code of the Apex Scheduler Controller :


            global class SynchroniseAccount Implements Schedulable


                        global void execute(SchedulableContext sc)





                        public void SyncAccount()


                                    List<Account> accLst = [Select id, name from Account Order by createddate Desc limit 7];

                                    for(Account ac : accLst)


                                                List<Contact> conLst = [Select id, name from Contact where AccountId=ac.id limit 1];



                                                            Contact con = new Contact(Lastname='LstName', AccountId=:ac.id);

                                                            insert con;






Hope this helps.