You need to sign in to do that
Don't have an account?
Reshmi Smiju
Issues with Lead to member Conversion
Hi,
While I am executing the class ‘LeadtoMember’, I am facing the the following issue.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadConversion caused an unexpected exception, contact your administrator: LeadConversion: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00Q9000000pNJH4EAO; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00Q9000000pNJH4) is currently in trigger LeadConversion, therefore it cannot recursively delete itself: []: Class.LeadtoMemberConversn.conversion: line 18, column 1
============================
The class is as follows.
public class LeadtoMemberConversn {
List<Lead> leads;
List<Member__c> members;
public LeadtoMemberConversn(List<Lead> leadList){
leads=leadList;
members= new List <Member__c>();
}
public void conversion(){
for(Lead l: leads){
Member__c member = new member__c();
member.Name = l.FirstName +” +l.LastName;
member.Email__c = l.Email;
members.add(member);
}
insert members;
List<Lead> todel= leads.deepClone(true);
delete todel;
}
public List<Member__c> getMembers(){
return members;
}
}
And the trigger is
trigger LeadConversion on Lead (before update){
List<Lead> leads= new List<Lead>();
for(Lead l:Trigger.new){
if(l.Status== ‘Member’){
leads.add(l);
}
LeadtoMemberConversn lmc= new LeadtoMemberConversn(leads);
lmc.conversion();
System.debug(‘values’+ lmc.getMembers());
}
}
While saving the Lead record’s status to Members, I am getting the error.
Thanks in Advance.
Reshmi.
While I am executing the class ‘LeadtoMember’, I am facing the the following issue.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadConversion caused an unexpected exception, contact your administrator: LeadConversion: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00Q9000000pNJH4EAO; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00Q9000000pNJH4) is currently in trigger LeadConversion, therefore it cannot recursively delete itself: []: Class.LeadtoMemberConversn.conversion: line 18, column 1
============================
The class is as follows.
public class LeadtoMemberConversn {
List<Lead> leads;
List<Member__c> members;
public LeadtoMemberConversn(List<Lead> leadList){
leads=leadList;
members= new List <Member__c>();
}
public void conversion(){
for(Lead l: leads){
Member__c member = new member__c();
member.Name = l.FirstName +” +l.LastName;
member.Email__c = l.Email;
members.add(member);
}
insert members;
List<Lead> todel= leads.deepClone(true);
delete todel;
}
public List<Member__c> getMembers(){
return members;
}
}
And the trigger is
trigger LeadConversion on Lead (before update){
List<Lead> leads= new List<Lead>();
for(Lead l:Trigger.new){
if(l.Status== ‘Member’){
leads.add(l);
}
LeadtoMemberConversn lmc= new LeadtoMemberConversn(leads);
lmc.conversion();
System.debug(‘values’+ lmc.getMembers());
}
}
While saving the Lead record’s status to Members, I am getting the error.
Thanks in Advance.
Reshmi.
Dont delete your lead records in the trigger. You can pass your lead ID to a future method. In that future method you can query the lead and delete it. Since future method is a seperate transaction it will allows you to delete.
Thanks
All Answers
The error is that you are trying to delete the current lead record in the same transaction which is not possible. thats why you are getting this error.
After converting to member, I just want to delete the lead set. Since leads points to Trigger.new, SF does not allow it to be deleted.So I treid to Cloning and then deleteing them. pls let me know, if i am doing wrong.If so, let me know, the one workaround for this.
Thanks much:)
Try with the below trigger and class
Below is the trigger to create a new member
Below is the future class to delete the converted lead
Hope this might help you.
Thanks
Thanks for ur response. But still i am facing the issue.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadConversion caused an unexpected exception, contact your administrator: LeadConversion: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00Q9000000pcL9lEAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00Q9000000pcL9l) is currently in trigger LeadConversion, therefore it cannot recursively delete itself: []: Class.LeadtoMemberConversn.deleteLead: line 22, column 1
* = Required InformationLead Information
Even if the Delete code is outsde the Trigger.new loop, the error message is same. which i am not understanding. Pls let me know your thought.
Thanks.
Dont delete your lead records in the trigger. You can pass your lead ID to a future method. In that future method you can query the lead and delete it. Since future method is a seperate transaction it will allows you to delete.
Thanks
Thanks