• developing
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi - I am trying to create a simple visualforce page that displays a dataTable of opportunities and then provides a commandLink within each row that when clicked changes the Forecast_Category__c field to 'Medium'. This works, however, only for the final row of the dataTable. I also tried this using a pageBlockTable and it worked, but only for the first record.

Thanks for any help -- Matt

Here is my page:

Code:
<apex:page controller="forecastController" title="Forecast Report">

<apex:form id="theForm">
<apex:dataTable value="{!OppsHigh}" var="opp" id="theTable" cellpadding="4">
<apex:column >
<apex:facet name="header">Link</apex:facet>
<apex:commandLink action="{!updateOpp}" value="M" id="theCommandLink" rerender="theTable">
<apex:param value="{!opp.id}" assignTo="{!oppId}" />
</apex:commandLink>
</apex:column>
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!opp.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Forecast Category</apex:facet>
<apex:outputText value="{!opp.Forecast_Category__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>

</apex:page>

 And, here is my controller:

Code:
public class forecastController {

public ID oppId;
public void setOppId(ID i) { oppId = i; }
public ID getOppId() { return oppId; }

public List<Opportunity> getOppsHigh() {
List<Opportunity> opps = [select
id,
name,
CloseDate,
Type,
Forecast_Category__c
from Opportunity
where Forecast_Category__c = 'High'];
return opps;
}

public void updateOpp() {
Opportunity opp = [select
id,
name,
CloseDate,
Type,
Forecast_Category__c
from Opportunity
where id =:oppId limit 1];

opp.Forecast_Category__c = 'Medium';
update opp;
}

}