+ Start a Discussion

test trigger after insert Lead and Account

Is it possible to call  two trigger on a test ?

My problem is that I must insert account to test my trigger after insert Lead and I have too a trigger after insert account.

When I test my class, the first trigger is tested but not the second and my code isn't correctly covered.


How can I not run trigger for the insert of account which is just initialization and run the trigger for the insert of lead ?






Your trigger will be called whenever you have performing any DML operation on that Object record inside the Test Method. So since you are inserting account your trigger on Account Object is called first. Now if you are inserting the Lead object record inside the test method and you trigger having insert condition on Lead Object then your Lead trigger must be called.



Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


Indeed when i execute my test class, the trigger for the account when i insert account but the trigger for the lead don't.


public class TestinsertLead {
     static testMethod void TestInsertWithAccount(){
        List <Account> acc = new List<Account>();
        for(integer i = 2; i<4; i++){
           Account account= new Account(
            Salutation = '',
            FirstName ='',
            LastName = 'test',
            Adresse_mail__c = 'test'+i+'@mail.com',//test2@mail.com, test3@mail.com
            PersonLeadSource = 'Newsletter');
    insert acc;System.debug('insertion des comptes initiaux ok');
    //début du test 
    Test.startTest(); system.debug('start test');
    List <Lead> newLeads= new List<Lead>();
    for(integer i = 2; i<4; i++){
        Lead lead = new Lead(
        Salutation = 'M.',
        FirstName ='Hélène',
        LastName = 'test',
        Adresse_mail__c = 'test'+i+'@mail.com',//test1@mail.com, test2@mail.com
        LeadSource = 'Newsletter');
    insert newLeads;System.debug('insertion des leads test ok');
    Test.stopTest() ;



up please 

Anybody knows why my trigger don't run when I call it a second time ?