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
SYM12SYM12 

Need Help to find the Logic using Maps or anything

Hi All ,

 

I am stuck to impliment a logic... below is the requirment,,

i have 3 objects( Leads , 2 custom(Virtual Numbers and Lead Virtuals)

 I have a campaign and in that campaign i have 1000+ leads......

there is button(visualforce button) on campaign( Assign Numbers) , when i click on the the button...

it will search all the leads in the campaign and  for each lead get his Area code(for eg. if Phone no is((408)512-2626) then get the 408)

For each  Area code eg 408 get the virtual number and put that Virtual no into the one of the custom field on lead object(Virtual_Number__c).

Also get each Associated Lead with Virtual no Id's and create a new lead Virtual.

  if a virtual number of a particular Area code is not avialable then than create a task.

 

If i impliment this logic for a single lead that works fine but i am getting hard time as bulk asigning

 

please see the logic below for assigning no to single lead....

 

Lead l2 = [Select Id,Status,Phone,Virtual_Number__c,FCCampaign__c,
                                  Number_type__c,IsProvisioned__c From Lead where Id = :id];
    if(l2.Status != 'New'){
        ReturnCode = 'Lead Status should be New ';
              return null;
    }
    else{
    string temp;
             temp = l2.Phone.substring(0,5);
             temp = temp + '%';
             list<Virtual_Number__c> v1 =    [Select Virtual_Number__c, Virtual_Number_Staus__c, Id
                             From Virtual_Number__c where Virtual_Number__c like :temp
                                      and Virtual_Number_Staus__c = 'Ready to Assign' limit 1];
                      System.debug('After VN Number................' + v1);
         FCCampaign__c F1 = [Select Id,Start_Trial_Date__c from FCCampaign__c where Id = :l2.FCCampaign__c];        
             Lead_Virtual__c vr = new Lead_Virtual__c();                        
                   if (v1.size()>0){
                       l2.Virtual_Number__c = v1[0].Virtual_Number__c;
             l2.Status = 'Trial';
             l2.Provisioning_Status__c = 'Provisioned';
           //  l2.Active__c = true;
             l2.Start_Trial_Date__c = F1.Start_Trial_Date__c;
             l2.IsProvisioned__c = true;
            // l2.End_Trial_Date__c = System.today()+ 14;
             v1[0].Virtual_Number_Staus__c = 'Assigned';
            
             vr.Lead__c = l2.Id;
             vr.Virtual_Number__c = v1[0].Id;
             vr.Status__c = 'Active';
                  
                   try{
                       update l2;
                       update v1;
                       insert vr;
                       PageReference detailPage = (new ApexPages.StandardController(L1)).view();
                   detailPage.setRedirect(true);
                   return detailPage; 
                   }catch(exception e){
                       System.debug('Error:' +e);
                       Returncode = 'SFDC Error:' +e;
                       return null;
                   }}
                   else{
             ReturnCode = 'Virtual Number is not available for lead area code: Please contact Twilio';
             l2.Provisioning_Status__c = 'Pending';
             update l2;
              return null;
                   }
}
    }
public PageReference okay(){
        PageReference detailPage = (new ApexPages.StandardController(L1)).view();
     detailPage.setRedirect(true);
     return detailPage;
   
    }
}

 

Creating task is not impliment till now in above code

Here chalanges in bulk assigning  are that how to track each with virtual number with the lead and also how to create lead virtuals with the particular lead and virtual number.

If i take leads in a list and loop the virtual number with particular area code then it will cross the SOQL limits.

I want to implimnet logic in such a way that i can update approx 800 in a time in 1 shot( as i can use @future in my class)

 

Any help  will be appriciated

 

Thanks