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
priya bhawna shettypriya bhawna shetty 

opportunity stagename update by comparing old and new value

hello guys
hope all doing well
pls help me out
i displayed list of opportunity names along with Editable input field stagenames parallelly  so when i enter any stagename and after clicking save ,only modified opportinities should be updated, not all ,
heres the process i did
1.for previous value of stagename i have taken map    i.e with map.  map<id,string> map9=new map<id,string>();  id=opportunity id                   and string=stagename.
2.in for loop i put if condition comparing previous value and current value.
3.now i throwed all map values to list  by declaring new list.
4.i updated opportunity in new list.
5.i did all this in "hitme" button  method

HERES MY PAGE AND CONTROLLER:
<apex:page controller="opportunitydisplaycon9" id="thePage">

<apex:form >
<apex:pageBlock >
                <apex:pageBlockButtons >
                 <apex:commandButton action="{!hitme}" value="hitme"/>
                </apex:pageBlockButtons>
        <apex:dataTable value="{!opportunity}" var="opp" id="theTable"   styleClass="tableClass">
                <apex:facet name="caption">opportunity Details</apex:facet>
                <apex:column >
                        <apex:facet name="header">opportunity Name</apex:facet>
                         <a href="/{!opp.Id}">{!opp.name}</a>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">opportunity stage</apex:facet>
                        <apex:inputField value="{!opp.stagename}"/>
                </apex:column>
              
        </apex:dataTable> 
</apex:pageBlock>
</apex:form>
</apex:page>

public class opportunitydisplaycon9 {
public List<opportunity> opp9;
map<id,string> map9=new map<id,string>();
    public PageReference hitme() {
     opportunity opp;
      for(opportunity opp:opp9)
      {
       if(opp.stagename!=map9.get(opp.id).stagename)
        {
         list<opportunity> list9=new list<opportunity>();
         list9.addall(map9);
        update opp9;
        return null;
    }

 
   public List<opportunity> getopp9()
   {

        opp9 = [select name,stagename from opportunity limit 10];

        return opp9;

   }

}
Ramu_SFDCRamu_SFDC
You can probably use wrapper class for this requirement. Please review the below articles on how to implement wrapper class

http://blog.cloudclickware.com/2013/05/28/record-selection-with-a-wrapper-class-in-apex/
http://www.minddigital.com/what-is-wrapper-class-and-how-to-use-it-in-salesforce/
http://blogforce9.blogspot.in/2013/06http://salesforce.stackexchange.com/questions/11191/just-update-when-a-specific-field-changes/wrapper-classes-wrap-it-up-with-wrapper.html

Fire the trigger only on particular field update

http://stackoverflow.com/questions/8671504/fire-a-update-trigger-when-particular-field-is-updated