You need to sign in to do that
Don't have an account?
Dorel4
Apex Trigger for Lead Assignment help
I need help creating an Apex trigger to get the lead assignment rule to trigger on our imported leads. I need it to run on all leads and I am not sure how to get it to work. thank you
trigger LeadAssign on Lead (after update)
{
List<Id> lIds=new List<id>();
For (lead l:trigger.new){
if (l.IsConverted==False){
lIds.add(l.Id); }
}
if (AssignLeads.assignAlreadyCalled()==FALSE){
system.debug('Assign already called? '+AssignLeads.assignAlreadyCalled());
AssignLeads.Assign(lIds);
}
}
public global class AssignLeads{
public static Boolean assignAlreadyCalled=FALSE;
public static boolean assignAlreadyCalled(){
return assignAlreadyCalled;
}
@future
public static void assign(List<Id> lIds){
assignAlreadyCalled=TRUE;
List<Lead> leads=[SELECT Id FROM Lead WHERE Id IN: lIds];
For (lead l:leads){
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
l.setOptions(dmo);
}
update(leads);
}
}
trigger LeadAssign on Lead (after update)
{
List<Id> lIds=new List<id>();
For (lead l:trigger.new){
if (l.IsConverted==False){
lIds.add(l.Id); }
}
if (AssignLeads.assignAlreadyCalled()==FALSE){
system.debug('Assign already called? '+AssignLeads.assignAlreadyCalled());
AssignLeads.Assign(lIds);
}
}
public global class AssignLeads{
public static Boolean assignAlreadyCalled=FALSE;
public static boolean assignAlreadyCalled(){
return assignAlreadyCalled;
}
@future
public static void assign(List<Id> lIds){
assignAlreadyCalled=TRUE;
List<Lead> leads=[SELECT Id FROM Lead WHERE Id IN: lIds];
For (lead l:leads){
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
l.setOptions(dmo);
}
update(leads);
}
}
All Answers
can you give me more information, from which view/screen you will be importing these date. It is Data Loader or Import Wizard? You will be importing or updating too?
As first i do not know unswer to your issue i saw couple of change that i will do.
1. You have parameter after update, but you mentioned that you will import data
2. If you have more than 50000 data then your calling will exiced government limits, in this case you can use batch jobs.
Thank you for looking at my problem. We are importing leads using Apex Code, written by a consultant. Currently none of these leads are going into the queues created by our lead assignment rules. The rules only trigger when the leads are manually entered. I am fairly new at writting code and followed some of the posts I found. I am not sure how to fix this, so our users can process leads using the queue.
oks so as i understand you have your custom Visualforce page and in behind some logic in apex classes. When you are inserting data you do not have validation check.
Second case is that if you are inserting data manually your validation rule is turn on and check data automatically.
In this case you can only rebuild their apex class and add there your condition.
Paste me their apex class that appear to your visual force page.
Thank you
or what the existing validation rules is doing.
Thank you