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
Chittineni SandeepChittineni Sandeep 

How to write a test class for below example for loop??

public void Save()
       insert pat;            
        for(wrapperservay wl : wrp)
            Answer__c ua = new Answer__c();       //From here code is not covered.      
            ua.Name = wl.Name;
             ua.Questionn__c = wl.QuestionId;                  
           insert ua;                       
            pat=new Answer__c();                                              

Please help guys from this problem

Thanks in Advance,


Amit Chaudhary 8Amit Chaudhary 8
Please post your full class and test class.
For above for loop you need to create test data according to wrapper class
After creating test data for the wrapperservay class in your test method, then call the save method to then confirm the new Answer__c records were created for each wrapperservay.

I would recommend building a list of answer__c records then do the dml statment on the list to avoid hitting dml limits.