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
Art SaberArt Saber 

VF Page with extension help

I'm trying to build a VF Page with a standard controller "Opportunities" and extension that can update fields from Accounts.

This is my VF Page:

<apex:page standardcontroller="Opportunity" sidebar="true">
    <apex:form >
     <apex:pageblock >
      <apex:commandButton value="Save" action="{!save}" rerender="error"/>
      <apex:commandButton value="Quick Save" action="{!quicksave}" rerender="error"/>
      <apex:commandButton value="Cancel" action="{!cancel}" rerender="error"/>
      </apex:pageblock>
      <apex:pageBlock mode="edit">
          <apex:pageBlockSection columns="2" showHeader="true" title="{!opportunity.name}">
              <apex:inputField value="{!Opportunity.Schedule_Type__c}" required="false"/>
              <apex:inputField value="{!Opportunity.LOI_In__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Amount}" required="false"/>
              <apex:inputField value="{!Opportunity.Schedule_Amount__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Deposit_Amount__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.SicDesc}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.Business_Start_Date__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.AnnualRevenue}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.Tangible_Net_Worth__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.EBITDA__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Lease_Term__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Base_Lease_Term_Implicit_Interest__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Lease_Type__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Equipment_Location__c}" required="false"/>
              <apex:inputField value="{!Opportunity.account.SP_Rating__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Account.SP_Outlook__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Risk_Rating__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Residual_Ceiling__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Residual_Floor__c}" required="false"/>
              <apex:inputField value="{!Opportunity.LTH_Recommendation__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Most_Recent_Audit__c}" required="false"/>
              <null>
              </null>
              <apex:inputField value="{!Opportunity.Strengths_of_Transactions__c}" required="false"/>
              <apex:inputField value="{!Opportunity.Primary_Challenge__c}" required="false"/>
         </apex:pageBlockSection>
      </apex:pageblock>
    </apex:form>
</apex:page>



I've created an apex class in sandbox (not all account fields on VF page is in apex class yet since I'm trying to test it out):

public class CreditExtension {
    public ApexPages.StandardController myAccountController {get; set;}
    public Account Account {get; set;}
    
    public ApexPages.StandardController standardOpportunityController;
    
    public CreditExtension(ApexPages.StandardController cntrl){
        
        standardOpportunityController = cntrl;
        
        Opportunity con = (Opportunity)cntrl.getRecord();
    Account = [select SP_Outlook__c from Account where id = :con.Account.id] [0];
    Account = [select AnnualRevenue from Account where id = :con.Account.id] [0];
    Account = [select SP_Rating__c from Account where id = :con.Account.id] [0];
    
    }
public pagereference doSaveAll () {
    standardOpportunityController.save();
    myAccountController.save();
    return null;
}
}


When trying to deploy it I'm getting errors saying code coverage is 0%. 

Questions: How to resolve code coverage issue, and am I on the right track here with what I'm trying to ahieve?
Alain CabonAlain Cabon
Hello,

Where is your class of test for the class CreditExtension? There is no "default' tests. You need to create a new class for testing the class CreditExtension with annotations (@isTest) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
Art SaberArt Saber
Thank you for linking me to the documentation. Follow directions, I ended up getting stuck. Seems like the test gets stuck on waiting for response from server. User-added image
Art SaberArt Saber
Test-->New Run
Alain CabonAlain Cabon
This is not a class of test. Your VF doesn't use your class. All is wrong. That cannot work.

A class for testing SALESFORCE.COM CONTROLLER EXTENSIONS is like that:

http://blog.jeffdouglas.com/2010/06/02/testing-salesforce-com-controller-extensions/

Jeff Douglas's blog is a reference site for SF developpers.
Art SaberArt Saber
I was able to deploy the apex class. Seems like the code for the class isn't resolving the issue. Can you take a look at it? I've added extensions="CreditExtensionThree" to the vf page above. 
User-added image