• Biz Zaveri
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi,

I'm writing test coverage for a trigger that, by all other accounts, is working fine, and yet the system.debug messages just seem to stop working after certain DML calls (as you can see below I'm obviously trying to assess a SOQL query limit problem). In the code below the debug logs show all of the system.debugs *except* for the very last one just after the final dml update. What sort of thing could be causing this? I get no error messages in any of the logs, the Test Coverage is running fine, the code runs fine ... This method inserts fine but breaks on the update, and I have another method that breaks on the insert. Certainly there might be some specific problem buried in the trigger but I'd like a general sort of lead before digging into that because I have absolutely no *sense* of *how* to start sniffing right now.

            Opportunity testOpp1 = new Opportunity ();
            testOpp1.RecordTypeId = giftInKindRecordTypeId;
            testOpp1.Name = 'TestGIK1';
            testOpp1.AccountId = donorAcct.Id;
            testOpp1.StageName = 'Received';
            testOpp1.CloseDate = System.Now().Date();
            testOpp1.Goal_Credit_Date__c = System.Now().Date();
            testOpp1.GIK_Fund__c = 'General Fund';
            testOpp1.GIK_Entity__c = 'Stand for Children, Inc. (C3)';
            testOpp1.GIK_Community__c = 'Gresham';
            testOpp1.InKind_Estimated_Value__c = 50;
            testOpp1.Description = 'random text';
            System.debug('Total Number of SOQL Queries just before inserting: ' +  Limits.getQueries());
            insert testOpp1;
            System.debug('Total Number of SOQL Queries after inserting: ' +  Limits.getQueries());
    
            testOpp1.StageName = 'Pending';
            update testOpp1;
            System.debug('Total Number of SOQL Queries - pending: ' +  Limits.getQueries());
            testOpp1.StageName = 'Received';
            //update testOpp1;
            System.debug('Total Number of SOQL Queries - received again but not updated: ' +  Limits.getQueries());
            testOpp1.StageName = 'Pending';
            update testOpp1;
            System.debug('Total Number of SOQL Queries - pending again: ' +  Limits.getQueries());
            testOpp1.StageName = 'Received';
            update testOpp1;
            System.debug('Total Number of SOQL Queries - received again AND updated: ' +  Limits.getQueries());            
            Test.stopTest();

Thanks!
Nick
I'm trying to write test class, for an apex code.  I do not understand  why the code coverage is yet  60% . Can someone help me? thank you

public class ModuloIncaricoInteraziendaleCtrl {
        
    private Quote quote {get; set;}
    public List<Qlip> qlips {get; set;}
 
    public class QliP {
        
        public QuoteLineItem qli {get; set;}
        public List<Partecipazione__c> partecipazioni {get; set;}
        public integer numeropartecipazioni {get; set;}
        
        public QliP(QuoteLineItem qlix, List<Partecipazione__c> partecipazionix){
            this.qli = qlix;
            this.partecipazioni = partecipazionix;
            this.numeropartecipazioni = partecipazionix.size();
        }
        
    }
 
    public ModuloIncaricoInteraziendaleCtrl(ApexPages.StandardController Ctrl){
        
        if (!Test.isRunningTest()) {Ctrl.addfields(new list<string>{'QuoteLineItems', 'Account.Name'});}
        this.quote=(Quote)Ctrl.getRecord();
        
        List<Id> QuoteLineItemsId = new List<Id>();
        for (QuoteLineItem qli : quote.QuoteLineItems){
            QuoteLineItemsId.add(qli.Id);
        }
        
        List<QuoteLineItem> queryQLI = [SELECT Id, LineNumber, Product2.Name, Edizione__r.Name, Edizione__r.Data_inizio__c, Edizione__r.Data_fine__c, Edizione__r.Ha_Partecipazioni__c, TotalPrice, Importo_IVA__c, Totale__c FROM QuoteLineItem WHERE Id IN :QuoteLineItemsId];
        List<Partecipazione__c> queryPartecipazioni = [SELECT Id, Name, Voce_Preventivo__c, Referente__r.FirstName, Referente__r.LastName, Referente__r.MiddleName, Referente__r.Suffix, Referente__r.Posizione__c, Referente__r.Email FROM Partecipazione__c WHERE Voce_Preventivo__c IN :QuoteLineItemsId ORDER BY Voce_Preventivo__c];
        
        qlips = new List<QliP>();
        for (QuoteLineItem qli : queryQLI) {
            
            List<Partecipazione__c> suePart = new List<Partecipazione__c>();
            integer NpartIgnote = 0;
            for (Partecipazione__c p : queryPartecipazioni){
                if(p.Voce_Preventivo__c == qli.Id){
                    if(p.Referente__c == NULL){
                        NpartIgnote++;
                        Contact cont = new Contact(LastName = 'Nominativo da comunicare ' + NpartIgnote + ' ' + Quote.Account.Name);
                        p.Referente__r = cont;
                        system.debug(p.Referente__r.Name);
                    }
                    suePart.add(p);
                }
            }
            Qlip newQlip = new QliP(qli, suePart);
            qlips.add(newQlip);
        }
        
    }

}


@istest
private class ModuloIncaricoInteraziendaleCtrl_Test {
    
    private static TestMethod void TestCostruttore(){
       
        List<Account> Lacc = new List <Account>();
        Account acc= new Account (FirstName='Antonio', LastName='Verdi', MiddleName='pippo',Type='Analyst' );
        insert acc;
        Lacc.add(acc);
        
        Edizione__c ed = new Edizione__c ( Name='test', Data_inizio__c=date.valueOf('2016-09-07'), Data_fine__c=date.valueOf('2016-09-07'),Ha_partecipazioni__c=true);
        insert ed;
       
        List <Contact> Lctc= new List <Contact>();
        Contact ctc= new Contact (LastName='Magneti', FirstName='Roberto', MiddleName='mauro', Suffix='Junior',email='k@email.it', posizione__c='direttore commerciale');
        insert ctc; 
        Lctc.add(ctc);
   
        List<Opportunity> l_opp = new List<Opportunity>();
        Opportunity opp = new Opportunity( AccountId=acc.id, Name='test', StageName='Prospecting',CloseDate=date.today(),Type='New Client',NextStep = 'Test',LeadSource = 'Business Development');
        insert opp;
        l_opp.add(opp);

     Product2 p2 = new Product2 (name='test',IsActive=true);
     List <Product2> Lp2 = new List <Product2>();
     insert p2;
     Lp2.add(p2);
     
     Id pricebookId = Test.getStandardPricebookId();

     List <PricebookEntry> Lpbe = new List <PricebookEntry>();
     PricebookEntry pbe = new PricebookEntry (Product2Id=p2.Id,IsActive=true,UnitPrice=1,Pricebook2Id=pricebookId);
     insert pbe;
     Lpbe.add(pbe);

List <Quote> Lqt = new List <Quote> ();
     Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'ciao', Pricebook2Id=pricebookId, ordine__c=false);
     insert preventivo;
        Lqt.add(preventivo);
        
 List<QuoteLineItem> Lqtl = new List<QuoteLineItem> ();
   QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id, quantity=1, unitprice=1, PricebookEntryId=pbe.id, Product2Id=p2.id, Edizione__c=ed.id );
   insert qtl;
    Lqtl.add(qtl);
      
     Partecipazione__c pt = New Partecipazione__c(stato__c='partecipante',Voce_preventivo__c=qtl.id, referente__c=ctc.id);
    insert pt;   
   List <Partecipazione__c> Lpt= new List <partecipazione__c> ();
     Lpt.add(pt);
        
         Partecipazione__c pt2 = New Partecipazione__c(stato__c='partecipante',Voce_preventivo__c=qtl.id, referente__c=ctc.id);
    insert pt2; 
     
       pt.Voce_Preventivo__c = qtl.Id;
        pt.Referente__c = null;
        pt.referente__c= contact;
         update ctc;
        
        system.debug(pt.Referente__r.Name);
        
        pt2.Voce_Preventivo__c = qtl.Id;
        pt2.Referente__c = null;
        pt2.referente__c= contact;
        update ctc;
        
        system.debug(pt2.Referente__r.Name);
        
     
        
    ApexPages.StandardController Controller = new ApexPages.StandardController(preventivo);
        
    ModuloIncaricoInteraziendaleCtrl stdController = new  ModuloIncaricoInteraziendaleCtrl(controller);
        
    ModuloIncaricoInteraziendaleCtrl.QliP prova = new ModuloIncaricoInteraziendaleCtrl.QliP(qtl,Lpt);
    
    } 
}