Visualforce Mass Edit Opp help - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Aaron PersichAaron Persich 

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>
Joseph BauerJoseph Bauer
The issue is because you have a cross object here:
<apex:inputField value="{!opp.account.Account_Rank__c}"/>

The opportunity fields are available since you are using the stand opp controller but it doesn't query all of the account fields so it won't be able to store Account Rank because it didn't query for that field. I would solve this by making a select list instead of inputField and you can either hard code the values or use a field set to get the picklist fields. Then when the user saves you can query for the account record and update it's account rank with the selected value from the picklist.
Aaron PersichAaron Persich
Thanks for the reply Joseph. I am very new to visualforce and code. Do you think you can show me in the code on what I need to change?
Joseph BauerJoseph Bauer

 

You can change the inputField that I specified above to:
 
<apex:inputField value="{!opp.Account}" />
<apex:selectList value="{!newAccountRank}" size="1">
    <apex:selectoption itemLabel="Account Rank" itemValue="accountrank1" />
    <apex:selectoption itemLabel="Another Account Rank" itemValue="accountrank2" />
 </apex:selectList>

I'm not sure what your apex code looks like so I can't really be specific with how to change it but in apex do this when the button is clicked (the form is submitted):

 
// put this up with the other members of the class
public String newAccountRank {get; set;}

// this goes in the form submission logic
Opportunity opp = (Opportunity) stdCtrl.getRecord();

// then we can query which account was selected to get Account_Rank and then update it
Account acc = [SELECT Account_Rank__c FROM Account WHERE Id = :opp.AccountId];
acc.Account_Rank__c = newAccountRank;
update acc;


Also add this logic to your controller so you can reference stdCtrl to get the record that was selected:
 
//this goes up with the member variables
private ApexPages.StandardController stdCtrl;

public GenerateValuationPDFController(ApexPages.StandardController std) {
        stdCtrl = std;
}

 
Aaron PersichAaron Persich
Hi joesph, 

I very new to code and visualforce pages.  I was told to write a controller extention and then add it to the visualforce code.  I was provided with this extension controller but it does not work when I try to save it.  

What do you think the best approach here is?

Error:  Error: Compile Error: expecting a semi-colon, found 'udpate' at line 21 column 4

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;

  } 

}
Joseph BauerJoseph Bauer
put a semi-colon (;) after update opp on line 21.
 
update opp;

 
Aaron PersichAaron Persich
Thanks.  I added the semicolon but now I am getting another error

Error: Compile Error: expecting a semi-colon, found 'new' at line 11 column 11
Joseph BauerJoseph Bauer
Can you put the code inside the < > tags. Just click the button in the text area editor.
Aaron PersichAaron Persich
Hi Joseph,

Thanks again for helping me here.  I got the extension controller to work but when I update my VF pge I get the below error.  Do you think you can help me out with this as well?

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>