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 

Visualforce Mass Edit Opp help

Hello,
 
I am working on building a “Mass Edit Opps” visualforce button on the opportunity list views and I need some help with the visualforce page.  The page allows the user to edit multiple Opportunity fields and one Account field.  The opportunity field updates work but the one Account picklist field labeled “Account Rank” does not make the update on the account.  The field shows on the page but will not make the update when I hit save. 
 
How can I get this to work?  Any help is much appreciated
 
Here is the visualforce code

<apex:page standardController="Opportunity" 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="{!save}"/>
<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>
Best Answer chosen by Aaron Persich 9
Pankaj MehraPankaj Mehra
Hi  Aaron Persich 9,

Standard opportuntiy save button will not save account record associated with opportunity you need to created a extension, you can keep all the code as it is and create a new class set as extension on current VF and in extension you have to explicitly save Account record

Page code will look like this
 
<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>

        ..... 
        Same Code 
        .....

        </apex:column>


</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Extension class will look like this:

 
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; 
  }


}

In case Account is not updated then create a String variable in Apex class and add a apex select option instead of <apex:inputField value="{!opp.account.Account_Rank__c}"/>  . You also need to get the picklist values 
<apex:actionSupport event="onchange" action="{!accountRank}" rerender="cases_table"/>
<apex:selectOptions value="{!items}"/>
</apex:selectList>

Thanks
 

All Answers

Pankaj MehraPankaj Mehra
Hi  Aaron Persich 9,

Standard opportuntiy save button will not save account record associated with opportunity you need to created a extension, you can keep all the code as it is and create a new class set as extension on current VF and in extension you have to explicitly save Account record

Page code will look like this
 
<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>

        ..... 
        Same Code 
        .....

        </apex:column>


</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Extension class will look like this:

 
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; 
  }


}

In case Account is not updated then create a String variable in Apex class and add a apex select option instead of <apex:inputField value="{!opp.account.Account_Rank__c}"/>  . You also need to get the picklist values 
<apex:actionSupport event="onchange" action="{!accountRank}" rerender="cases_table"/>
<apex:selectOptions value="{!items}"/>
</apex:selectList>

Thanks
 
This was selected as the best answer
Aaron Persich 9Aaron Persich 9
Thanks for helping me here Pankaj.  I tried to add the extension class and recieved the below error.  Do you know how I can resolve this?

Error: Compile Error: expecting a semi-colon, found 'udpate' at line 21 column 4
Pankaj MehraPankaj Mehra
Hi Aaron, 

You can see at the line number mentioned in the error semicolon is missing after update opp, also I just wrote the class directly here so this is not compiled you need to fix such minor issues
Aaron Persich 9Aaron Persich 9
Hi Pankaj,

I tried to add the semicolon after the update opp and I still get the same error.  I have no idea how to code and I am not sure what I am doing here

udpate opp;

    udpate new Account(Id = opp.AccountId , Account_Rank__c = opp.Account.Account_Rank__c );
 
Aaron Persich 9Aaron Persich 9
I added the semicolon after the update opp which seemed to work but now I am getting this error

Error: Compile Error: expecting a semi-colon, found 'new' at line 21 column 11
Pankaj MehraPankaj Mehra
Hi Aaron,

Replace line with below code:
udpate new Account(Id = opp.AccountId , Account_Rank__c = opp.Account.Account_Rank__c );

New code
Account acc = new Account(Id = opp.AccountId);
acc.Account_Rank__c = opp.Account.Account_Rank__c;
update acc;
Aaron Persich 9Aaron Persich 9
Thanks Pankaj,

I got the controller to save but when I try to add it to the visualforce page I get the below error.

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


<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>