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
Aaron Persich 9Aaron Persich 9 

Error: Compile Error: expecting a semi-colon, found 'new' at line 21 column 11

Hello,

I am very new to coding and have no idea what I am doing.  I am trying to build an extension controler but I keep getting errors.  The latest error is as follows:

Error: Compile Error: expecting a semi-colon, found 'new' at line 21 column 11

Controller

public class OpportunityExtension {
  public Opportunity opp{get; set;}
  public String accountRank {get; set;}
  public OpportunityExtension(ApexPages.StandardController stdCltr) {
    opp = (Opportunity) stdCltr.getRecord();

  }
  public void saverecord() {
    udpate opp;
    udpate new Account(Id = opp.AccountId ; Account_Rank__c = opp.Account.Account_Rank__c );

    //or
    //udpate new Account(Id = opp.AccountId , Account_Rank__c = accountRank );

  }
  public List<SelectOption> getItems() {

    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('','Select'));
    options.add(new SelectOption('Closed','Closed'));
    options.add(new SelectOption('New','New'));
    options.add(new SelectOption('Working','Working'));

    return options;
  }
}

Can someone please help me with this?  I am not sure what I am missing.  

Thanks in advance,

Aaron
Best Answer chosen by Aaron Persich 9
Amit Chaudhary 8Amit Chaudhary 8
Update your code like below
public class OpportunityExtension {
  public Opportunity opp{get; set;}
  public String accountRank {get; set;}
  public OpportunityExtension(ApexPages.StandardController stdCltr) {
    opp = (Opportunity) stdCltr.getRecord();

  }
  public void saverecord() {
    update opp;
   
    Account accObj = new Account(Id = opp.AccountId , Account_Rank__c = opp.Account.Account_Rank__c );
    update accObj ;

    //or
    //udpate new Account(Id = opp.AccountId , Account_Rank__c = accountRank );

  }
  public List<SelectOption> getItems() {

    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('','Select'));
    options.add(new SelectOption('Closed','Closed'));
    options.add(new SelectOption('New','New'));
    options.add(new SelectOption('Working','Working'));

    return options;
  }
}

Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Update your code like below
public class OpportunityExtension {
  public Opportunity opp{get; set;}
  public String accountRank {get; set;}
  public OpportunityExtension(ApexPages.StandardController stdCltr) {
    opp = (Opportunity) stdCltr.getRecord();

  }
  public void saverecord() {
    update opp;
   
    Account accObj = new Account(Id = opp.AccountId , Account_Rank__c = opp.Account.Account_Rank__c );
    update accObj ;

    //or
    //udpate new Account(Id = opp.AccountId , Account_Rank__c = accountRank );

  }
  public List<SelectOption> getItems() {

    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('','Select'));
    options.add(new SelectOption('Closed','Closed'));
    options.add(new SelectOption('New','New'));
    options.add(new SelectOption('Working','Working'));

    return options;
  }
}

Let us know if this will help you
 
This was selected as the best answer
Aaron Persich 9Aaron Persich 9
Hi Amit,

Thank you for looking into this.  I got the controler to work but when I update my visualforce page I am getting an error.  I am very new to code and do not know how to resolve this issue.  Any help is much appreciated.

Controller Extension

public class OpportunityExtension {
  public Opportunity opp{get; set;}
  public String accountRank {get; set;}
  public OpportunityExtension(ApexPages.StandardController stdCltr) {
    opp = (Opportunity) stdCltr.getRecord();
  }
  public void saverecord() {
    update opp;
    Account accObj = new Account(Id = opp.AccountId , Account_Rank__c = opp.Account.Account_Rank__c );
    update accObj ;

    //or
    //udpate new Account(Id = opp.AccountId , Account_Rank__c = accountRank );
  }

  public List<SelectOption> getItems() {

    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('','Select'));
    options.add(new SelectOption('Closed','Closed'));
    options.add(new SelectOption('New','New'));
    options.add(new SelectOption('Working','Working'));

    return options;
  }
}

ERROR Message when I try to update my visualforce page

Error: Unsupported attribute extension in <apex:page> in MassEditOpp2 at line 1 column 116

VF page

<apex:page standardController="Opportunity" extension="OpportunityExtension" recordSetVar="unused" sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >

Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.

</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!saverecords}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="opp" id="table">
<apex:column headerValue="Name">
<apex:inputField value="{!opp.name}"/>

</apex:column>

 <apex:column headerValue="Account Rank">
          <apex:inputField value="{!opp.account.Account_Rank__c}"/>
        </apex:column>

        <apex:column headerValue="Channel Partner">
          <apex:inputField value="{!opp.Channel_Partner__c}"/>
        </apex:column>

        <apex:column headerValue="Project Name">
          <apex:inputField value="{!opp.Project_Name__c}"/>
        </apex:column>

        <apex:column headerValue="Evaluation Period - Start Date">
          <apex:inputField value="{!opp.Evaluation_Period_Start_Date__c}"/>
        </apex:column>

        <apex:column headerValue="Success Criteria for Evaluation">
          <apex:inputField value="{!opp.Success_Criteria_for_Evaluation__c}"/>
        </apex:column>

        <apex:column headerValue="Customer Pain Points">
          <apex:inputField value="{!opp.Customer_Pain_Points__c}"/>
        </apex:column>

<apex:column headerValue="Amount">
<apex:inputField required="true" value="{!opp.amount}"/>
</apex:column>

        <apex:column headerValue="Budget">
          <apex:inputField value="{!opp.Budget__c}"/>
        </apex:column>

        <apex:column headerValue="Close Date">
          <apex:inputField value="{!opp.closeDate}"/>
        </apex:column>

        <apex:column headerValue="Probability">
          <apex:inputField value="{!opp.Probability}"/>
        </apex:column>

        <apex:column headerValue="Weighted Revenue">
          <apex:inputField value="{!opp.Weighted_Revenue__c}"/>
        </apex:column>

        <apex:column headerValue="Champion">
          <apex:inputField value="{!opp.Champion__c}"/>
        </apex:column>

        <apex:column headerValue="Technical Issues">
          <apex:inputField value="{!opp.Technical_Issues__c}"/>
        </apex:column>

        <apex:column headerValue="Business Issues">
          <apex:inputField value="{!opp.Business_Issues__c}"/>
        </apex:column>

        <apex:column headerValue="Other Comments or Obstacles">
          <apex:inputField value="{!opp.Other_Comments_or_Obstacles__c}"/>
        </apex:column>

        <apex:column headerValue="Required Resources">
          <apex:inputField value="{!opp.Required_Resources__c}"/>
        </apex:column>

        <apex:column headerValue="SE Comments">
          <apex:inputField value="{!opp.SE_Comments__c}"/>
  </apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>