+ Start a Discussion
Debendra Ray 8Debendra Ray 8 

Tigger firing twice while converting a lead

Dear All,

I've written the below  trigger to validate the Lead before it's converted to an opportunity :

for (Integer i = 0; i < Trigger.new.size(); i++) {
                    List<Attachment> leadAttachmentLst = [select name from Attachment where PARENTID = :Trigger.new[i].id] ;
                    List<Customer_Visit_Report__c> cvrLeadLst = [select id from Customer_Visit_Report__c where Lead__c = :Trigger.new[i].id ];
             if(cvrLeadLst.size() == 0 ){
                 Trigger.new[i].addError('Please create Customer Visit Report for this Lead!');
             if(!(leadAttachmentLst.size() == 2) ){
                 Trigger.new[i].addError('Please attach the PIF & Dossier documents for this Lead!');
             for(Attachment attch :leadAttachmentLst){
                 if(!(attch.name.contains('PIF')||attch.name.contains('Dossier') ) ){
                     Trigger.new[i].addError('Please rename the PIF & Dossier documents as : <nameofthefilePIF> , <nameofthefileDossier>!');
          }catch(Exception e)
           System.debug('Error : ValidateLeadConversionPrerequisites ->'+ e);  

The issue is while this code works fine , however, this throws these errors again while I'm on the 2nd screen of Lead conversion - Ideally, this trigger should not have thrown these errors when all conditions are already met on the previous screen.

Please could someone provide a clue to circumvent this problem.

Thanks & Regards,

Debendra Ray