You need to sign in to do that
Don't have an account?
How to create bulk Leads(say 100) Leads at a time ?
Our need is to create almost 100 leads taking data from our custom object (Operation__c) of our previous clients on a particular condition at a time along with that a single email and a text message should go to each lead.
I have created one schedulable class which takes required data from Operation__c(Query on operation) of our previous clients and I am inserting leads through this schedulable class and the control then enter into our Lead creation trigger.
It works fine for 10 records creation but on 11th it hits the governer limits and throws a DML exception "TO Many SOQL Queries:101" which is quite obvious because as my single lead creation hits 10 queries(inside my lead creation)....indeed in a single transaction for 11 records creation 11records * 10queries(More than 100)...EXCEPTION.
Now my question is how can I create bulk leads for my existing clients ?
All Answers
Actually our Lead tigger is preety complex none of the query is inside a for loop the actual problem is the schedulable class which inserts leads is inserting as 1 Lead object at a time indeed 1 transaction and that is making a problem.
I have come up with a solution by creating these bulk leads by means of batch interface giving 100 scopsize ...worked for me(As a single transaction).
Here is that class which is inserting leads and being called froma schedulable class.
public with sharing class LeadNewAMCCreation {
list<operation__c> newOperation;
public void createNewLeadsForAMC(){
newOperation = [Select id,Contact_Name__c,Contact_Email__c,Phone_Number__c,Enquiry_for__c,
Contact_FirstName__c,Contact_LastName__c,Contact_Salutation__c,City__c,
ROC_Name__c,Incorporation_Date__c,Auth_Capital__c,Paid_Up_Capital__c,
Name,New_Company_Name__c,Company_Extention__c,CreatedDate,Owner_Name__c,
BDE_Name__c
from
Operation__c
where
Enquiry_for__c =: 'Pvt. Ltd. Registration'
AND
Incorporation_Date__c =: system.today()
AND
New_Company_Name__c =: 'ABC'];
system.debug('--newOperation--'+newOperation);
for(operation__c newOp : newOperation){
Lead newLead = new Lead();
newLead.Salutation = newOp.Contact_Salutation__c;
newLead.LastName = newOp.Contact_LastName__c;
newLead.FirstName = newOp.Contact_FirstName__c;
newLead.Contact_Name__c = newOp.Contact_Name__c;
newLead.Email = newOp.Contact_Email__c;
newLead.Phone = newOp.Phone_Number__c;
newLead.Enquiry_For__c = 'Pvt. Ltd. AMC';
newLead.User__c = '00590000000myQN';
newLead.OwnerID = '00590000000myQN';
newLead.Created_Through__c = 'BDE';
newLead.WorkFlowNumber__c = null;
newLead.CompliancePage__c = true;
newLead.City = newOp.City__c;
newLead.ROC_Name__c = newOp.ROC_Name__c;
newLead.Incorporation_Date__c = newOp.Incorporation_Date__c;
newLead.Auth_Capital__c = newOp.Auth_Capital__c;
newLead.Paid_up_Capital__c = newOp.Paid_Up_Capital__c;
newLead.BMCID__c = newOp.Name;
newLead.Operation_owner__c = newOp.Owner_Name__c;
newLead.Operations_Created_Date__c = newOp.createdDate;
newLead.Company = newOp.New_Company_Name__c +' '+newOp.Company_Extention__c;
newLead.BDE_Name__c = newOp.BDE_Name__c;
insert newLead;
system.debug('--newLead--'+newLead);
}
}
}