function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Afrose AhamedAfrose Ahamed 

how to bypass validation when lead convert

Hello All,
 When Lead convert if users choose Create New' then validation rule on lead needs to run if they choose 'Choose Existing' validation rule don't need to run. So i created check box on lead with unchecked.
Validation rule: AND(AfroseDev__By_Pass_Validation_Rule__c = True &&
ISBLANK(Email))


After that i created trigger to bypass validation rule. But its running on both 'Create New' and 'Choose Existing' please refer the below code. Please help how can i acheive this.
trigger LeadCurrencyTrigger on Lead ( Before Insert, Before Update, after insert,After Update) {
   list<id>OldAlloppid = new list<id>();//hold all opportunities ids in the list
    list<id>Convertedid = new list<id>();//hold currentConverted Opportunity Id in the list
    for(Opportunity op:[select id from Opportunity]){
        OldAlloppid.add(op.id);
        
    }
    
    for(lead l:trigger.new){
        Convertedid.add(l.convertedOpportunityId);
        
 // this condition will check the if current convertedoppid not in the existing opportunity records.
        if(OldAlloppid!=Convertedid)
        {
           
            System.debug('Convertedid'+Convertedid + 'oldMap'+OldAlloppid);
        if(l.IsConverted && trigger.isBefore){
			
            System.debug('im inside');
            l.AfroseDev__By_Pass_Validation_Rule__c = true;
        }
    }    
	
}  
}



Regards,
Afrose Ahamed M.G
PriyaPriya (Salesforce Developers) 

Hey Afrose,

Kindly check this link which exactly matches your requirement :- 
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A8KimSAF


Kindly mark it as the best answer if it helps.

Thanks & Regards,

Priya Ranjan

Afrose AhamedAfrose Ahamed

Hi @Priya,
Thanks for your reply. Actually i want to bypass the validation rule on the same object. when lead convert i want to bypass lead validation rule only when i choose existing Account.
Regards,

Afrose