You need to sign in to do that
Don't have an account?
Swami Deshanel
Question regarding Mass Convert Trigger
I have a mass convert trigger that when a lead is a Contacted it will get converted. When I test the trigger by changing the status of a lead to contacted, it works perfectly. However, when I mass upload leads, it converts all the records, not just those with a Contacted status. Please help
And on a side note, if you happen to have a test class that will conver this triggfer, that would save me heaps of time. Thanks in advance
Code Below:
trigger AutoConvert on Lead (after update) {
list<Lead> LeadsToConvert = new list<Lead>();
for(Lead myLead: Trigger.new){
if(!myLead.isConverted)
LeadsToConvert.add(myLead);
}
list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
for(Lead myLead : LeadsToConvert){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.convertedStatus = 'Contacted';
//Database.ConvertLead(lc,true);
lc.setDoNotCreateOpportunity(true);
leadConverts.add(lc);
}
if(!leadConverts.isEmpty()){
for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
Integer startIndex = i*100;
Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
for(Integer j=startIndex;j<endIndex;j++){
tempList.add(leadConverts[j]);
}
Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
for(Database.LeadConvertResult lcr : lcrList)
System.assert(lcr.isSuccess());
}
}
}
And on a side note, if you happen to have a test class that will conver this triggfer, that would save me heaps of time. Thanks in advance
Code Below:
trigger AutoConvert on Lead (after update) {
list<Lead> LeadsToConvert = new list<Lead>();
for(Lead myLead: Trigger.new){
if(!myLead.isConverted)
LeadsToConvert.add(myLead);
}
list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
for(Lead myLead : LeadsToConvert){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.convertedStatus = 'Contacted';
//Database.ConvertLead(lc,true);
lc.setDoNotCreateOpportunity(true);
leadConverts.add(lc);
}
if(!leadConverts.isEmpty()){
for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
Integer startIndex = i*100;
Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
for(Integer j=startIndex;j<endIndex;j++){
tempList.add(leadConverts[j]);
}
Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
for(Database.LeadConvertResult lcr : lcrList)
System.assert(lcr.isSuccess());
}
}
}
Error:Apex trigger AutoConvert caused an unexpected exception, contact your administrator: AutoConvert: execution of AfterUpdate caused by: System.AssertException: Assertion Failed: Trigger.AutoConvert2: line 28, column 1