1

I have a giant list of potential clients which I want to import into Leads. But I don't want to distribute all of them at one time. I would like to distribute a subset amount to the sales team every week. (let's say 50 a week)

I was thinking of maybe importing all of them at once into a custom object - and then somehow using a scheduled job to kick off every week to create the Leads from the entries. My problem is that I can't figure out how to only pull 50 every week.

Anybody got any suggestions on this ?

1 Answer 1

2

You could take this approach:

  1. Create a boolean field called Distributed in Lead object. (Or, you can consider from Lead Status itself)

  2. Create a schedule job which will run weekly and pull up those leads which are not distributed.

    SELECT Id, Name, OwnerId FROM Lead WHERE Distributed__c = false LIMIT 50

  3. Take this list and update OwnerId to a queue and Distributed__c = true

  4. Also, you may think of creating scheduled report to send to those queue members taking these last 50 lead records.

Code example:

global class WeeklyLeadProcessor implements Schedulable
{
    global void execute (SchedulableContext scx)
    {

        Group group = [Select Id, Name FROM Group 
                       WHERE Type = 'Queue' 
                       AND Name = 'Distributed_Queue']

        List<Lead> lstLead = [SELECT Id, Name, OwnerId 
                              FROM Lead 
                              WHERE Distributed__c = false LIMIT 50];
        for(Lead leadObj:lstLead)
        {
            leadObj.Distributed__c = true;
            leadObj.OwnerId = group.Id;
        }
        update lstLead;
    }
}
1
  • Thank you very much Santanu. That seems like the perfect solution. Can you show me some more of the code which is necessary here ?
    – Zoom_v
    Mar 17, 2017 at 21:40

You must log in to answer this question.

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