You need to sign in to do that
Don't have an account?
Abhilash Mishra 13
How to cover this code block
I was not able to cover the code block based on document object.. my sample code is.
how can i cover if block.
Thanks
Abhilash
public class testcontroller{ public void method1(){ list<document>docs; list<string>li=new list<string>() try{ docs=[select id from document where name !=null']; }catch(Exception e){ apexpages.addmessages(e); } } if(docs!null || !docs.isemprty()){ for(document d:docs) li.add(d.name); } }when writing test class i am not able to insert anty doucmet an always get docs as null
how can i cover if block.
Thanks
Abhilash
Well here not simple case. Best option from technical point of view is to extract Select query to separate method and pass list of resutls to tested method. So in unit test you could create Document sObjects (only in memory) and pass it to your method. You could even overrride this selector method and use it directly in tested method without passing any parametres.
Please try this and let me know.
-Thanks
Ashlekh Gera
your code is working final but its not covering the codeblock the value is still null.