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
MunmunMunmun 

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.....

hisrinuhisrinu

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

http://blog.sforce.com/sforce/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html

 

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

 

http://sites.force.com/appexchange/listingDetail?listingId=a0330000004mbxwAAA

MunmunMunmun

Hi  Thanks for reply ..

 

 

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

 

Pradeep_NavatarPradeep_Navatar

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)

                        {

                                    SyncAccount();

                        }

 

                        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];

                                                if(conLst.size()==0)

                                                {

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

                                                            insert con;

                                                }

                                    }

                        }

            }

 

Hope this helps.