• Art Saber
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 13
    Replies
Please help! Just started SFDC development. I've tried so many ways and looked at previously asked questions but can't figure out how to get the code right for an extension to a standardcontroller to be able to edit fields from Account and Opportunity on on VF page. 

VF Page User-added imageWhat does the extension have to look like for the VF page to update the Account fields??
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?
I would like to create a button on an opportunity detail page. The buttom will lead to a page to update fields, which the fields are sitting on the opportunity detail page and the account detail page. 

I do not know where to start on this. Help/direction will be much appreciated. 
Please help! Just started SFDC development. I've tried so many ways and looked at previously asked questions but can't figure out how to get the code right for an extension to a standardcontroller to be able to edit fields from Account and Opportunity on on VF page. 

VF Page User-added imageWhat does the extension have to look like for the VF page to update the Account fields??
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?
I would like to create a button on an opportunity detail page. The buttom will lead to a page to update fields, which the fields are sitting on the opportunity detail page and the account detail page. 

I do not know where to start on this. Help/direction will be much appreciated.