I have a requirement . I want to know the number of leads created for every 10 mins and if the leads are not created in last 10mins I want to get an email saying No leads are created in last 10 mins

Can anyone help me how to achieve this

1 Answer 1


You can achieve that by writing a scheduler. Once the scheduler runs then schedule it after 10 min times in apex. If you want to learn how to do it. Then you can follow below forum discussion.


In order to check if there are records which are created in last 10 mins you can use below code snippet.

DateTime pastTime = System.now().addMinutes(-10);

List<Lead> leadsCreatedInLast10Minutes = [Select Id from Lead WHERE CreatedDate >= : pastTime]

Now if the leadsCreatedInLast10Minutes.size() is equal to zero then you can send email.

  • Thanks for the response ! I Created URl in salesforce i.e services/apexrest/LeadData I Created this for every 10mins can I now hard code the url services/apexrest/LeadData/15Minutes or any minutes i want o get the count . Is it possible to Hardcode the url.
    – Revanth
    Apr 5, 2016 at 20:11
  • I don't understand why you had need to created apex rest service. Here only scheduler would have done the job. Apr 6, 2016 at 6:51

Not the answer you're looking for? Browse other questions tagged .