You need to sign in to do that
Don't have an account?

create a test case for PieWdgeData
I dont know why but this code works perfectly fine in Sandbox, but once I imported to production its says only 72 percent of it passes. I dont know how to write test cases
public class ClosedLostStages { public List<Opportunity> Stages {get; private set;} public Integer counterLost {get;private set;} public Integer counterWon {get;private set;} public Integer counterQuoteSent {get;private set;} public Integer counterOpportunityIdentified {get;private set;} public Integer counterBizOrderFormSigned {get;private set;} public Integer counterRTS {get;private set;} public Decimal Sum {get;private set;} public Double perLost {get;private set;} public Double perWon {get;private set;} public ClosedLostStages() { Stages = [Select Id, StageName, Amount, Name, Owner.Name FROM Opportunity WHERE StageName = 'Closed Lost']; counterLost = [ Select count() FROM Opportunity WHERE StageName = 'Closed Lost' ]; counterWon = [ Select count() FROM Opportunity WHERE StageName = 'Closed Won' ]; counterQuoteSent = [ Select count() FROM Opportunity WHERE StageName = 'Quote Sent' ]; counterOpportunityIdentified = [ Select count() FROM Opportunity WHERE StageName = 'Opportunity Identified' ]; counterBizOrderFormSigned = [ Select count() FROM Opportunity WHERE StageName = 'Biz Order Form Signed' ]; counterRTS = [ Select count() FROM Opportunity WHERE StageName = 'RTS' ]; Sum = counterWon + counterLost ; perLost = ((counterLost / Sum) * 100) ; System.debug(perLost + 'Lost percentage'); perWon = ((counterWon / Sum) * 100) ; System.debug(perWon + 'Won percentage'); } public List<PieWedgeData> getPieData() { List<PieWedgeData> data = new List<PieWedgeData>(); data.add(new PieWedgeData('Lost ', counterLost)); data.add(new PieWedgeData('Won', counterWon)); data.add(new PieWedgeData('Quote Sent', counterQuoteSent)); data.add(new PieWedgeData('Opportunity Identified', counterOpportunityIdentified )); data.add(new PieWedgeData('RTS', counterRTS)); data.add(new PieWedgeData('Biz Order Form Signed', counterBizOrderFormSigned)); return data; } public class PieWedgeData { public String name { get; private set; } public Integer data { get; private set; } public PieWedgeData(String name, Integer data) { this.name = name; this.data = data; } } }
Check this link to create sample test class for opportuniy.
http://salesforce.stackexchange.com/questions/36680/how-to-write-test-class-for-below-apex-class
Also you need to create a opportunity records for different counters you are getting using SOQL in constructor.
Then call function getPieData.
This should cover you code.
These are just logical steps mentioned here, if you find any error while writing please let me know and will help to sort it out.
Best Regars,
Rahul
I am not sure if your opportunity has any required fields. You need to populate those fields similar to name field. Please find code below. I have not tested it.There may be errors. Let me know how it goes. Also if you could paste Visualforce page related to this class I can help you more.
You will see this class when you go to develop > App Test Execution.
Execute CloseStageUnitTest class from App Test Execution to get see code coverage and success.
Regards,
Rahul
Hi Rahul,
even with the code above, it only passes 35 percent. in the production it fails and says only 73 percent was passed. I dotn understand when the code gives me no error what is the issue. here is the VF page
Please add system.debug after each statement to check it.
example
Let me know how it goes.
Thanks
Check this article to monitor debug logs
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_debugging_debug_log.htm
This will help you how to debug your code.
Regards