You need to sign in to do that
Don't have an account?
gbrown
Need help increasing code coverage
I'm having a difficult time to get my code coverage increased (I'm still a newb on the dev end).
My class is working and the test class passes, but I'm not able to piece it all together. Any help?
My Class to display values on a VF page...
public class ascSummary{ public ascSummary() { } public ascSummary(ApexPages.StandardController controller) { } public Visit__c getVisit() { //Retrieve Audit Results based on Id parameter of this page return [Select Id, Visit__c.Account__c, Visit__c.Contact__c, Visit__c.Visit_Date__c, Visit__c.Pre_audit_score__c, Visit__c.Workshop_Score1__c, Visit__c.Total_3_0v2__c, Visit__c.Total_4_0v2__c, Visit__c.Total_5_0v2__c, Visit__c.X1_0__c, Visit__c.X2_0__c, Visit__c.X3_0__c, Visit__c.X4_0__c, Visit__c.X5_0__c, Visit__c.Total_Percent__c, Visit__c.Total_Audit_Score__c from Visit__c j where Id = :ApexPages.currentPage().getParameters().get('id') ]; } }
My test class..
@isTest private class ascSummaryTestClass { static testMethod void validateascSummary() { visit__c v = new visit__c (Account__c='001c000000Qm4kp', Contact__c = '003c000000N7Bl0'); insert v; // Retrieve the contact from the visit v = [SELECT Contact__c FROM Visit__c WHERE Id =:v.Id]; System.debug('Contact after visit created: ' + v.Contact__c); } }
So I don't think you need a custom controller at all then...looks like you can just use the Standard Controller - even if the users have edit permissions, the page wil render as defined below as output text:
So change the page heading to:
And update all the Visit references to be Visit__c e.g.
When you call the page with Id= [ValidId], it will render for that record automatically, with no additional code.
Also, because it is a Standard Controller, you can also build a custom button that you can call directly from a detail page that will automatically render it in the correct context - just choose VisualForce page as the option
All Answers
You could either change your class so that your return statement is all on one line, or change your query in your test class retrieves all the fields in the above mentioned return statment.
Also, I would recommend that you do not hard code Ids in your test class. Instead, create and insert dummy records and use the Ids from your dummy records to create a test visit__c record.
Couple of questions, and then I think we can get it working fine...
Is this an extension to the Visit__c controller? Looks it is supposed to be, but if so, there are a few pieces missing. Once I know that, I can give you a working example of the extension and the test
Sent from my iPhone
Okay - can you post the basic page then...I think I need to see the use case for this class...
here is the visualforce page that I created to display results only, did not want the users to be able to edit the page.
So I don't think you need a custom controller at all then...looks like you can just use the Standard Controller - even if the users have edit permissions, the page wil render as defined below as output text:
So change the page heading to:
And update all the Visit references to be Visit__c e.g.
When you call the page with Id= [ValidId], it will render for that record automatically, with no additional code.
Also, because it is a Standard Controller, you can also build a custom button that you can call directly from a detail page that will automatically render it in the correct context - just choose VisualForce page as the option